>  Q&A  >  본문

Python 的 time 和 datetime 几个 API 函数的全称问题?

2016/11/7

问题

几个标准库 API 函数的全称( 先纯主观吐槽下, Python 标准库中真的有很多令人讨厌的缩写 )
( 新时代了, 除约定俗成的那些单词外如 min,max, 真心不提倡随便对单词进行缩写了 )

注释中附我的的猜想

真正问题是:

  1. 当遇到这种不明觉厉的缩写

  2. 文档中又没有说得很清楚的时候

  3. 去 Google, 发现好像只有自己担心这个问题的时候

是怎么解决的?

time.asctime([t]) # asCTime?  asConvertedTime?  aStringConvertedTime?
Convert a tuple or struct_time representing a time as returned by gmtime() or localtime() to a 24-character string of the following form: 'Sun Jun 20 23:21:05 1993'. If t is not provided, the current time as returned by localtime() is used. Locale information is not used by asctime().

Note
Unlike the C function of the same name, there is no trailing newline. # 这里好像给了提示

Changed in version 2.1: Allowed t to be omitted.
time.ctime([secs])  # convertedTime? currentTime? convertTime?
Convert a time expressed in seconds since the epoch to a string representing local time. If secs is not provided or None, the current time as returned by time() is used. ctime(secs) is equivalent to asctime(localtime(secs)). Locale information is not used by ctime().

Changed in version 2.1: Allowed secs to be omitted.

Changed in version 2.4: If secs is None, the current time is used.
datetime.astimezone(tz)  # asTimezone? adjustTimezone? ( 如果是这个, 谁能告诉 adjust-->as 到底是啥典故? )
Return a datetime object with new tzinfo attribute tz, adjusting the date and time data so the result is the same UTC time as self, but in tz‘s local time.

tz must be an instance of a tzinfo subclass, and its utcoffset() and dst() methods must not return None. self must be aware (self.tzinfo must not be None, and self.utcoffset() must not return None).
calendar.timegm(tuple) 
An unrelated but handy function that takes a time tuple such as returned by the gmtime() function in the time module, and returns the corresponding Unix timestamp value, assuming an epoch of 1970, and the POSIX encoding. In fact, time.gmtime() and timegm() are each others’ inverse. # 卧槽! 不看文档根本不会知道 timegm 是什么 ( 用 to_timestamp 多好)

New in version 2.0.

还有其他一些, 一时记不起来了, 待补充

另: time 和 datetime 的 API, 个人感觉略显混乱. 求「针对这 2 个模块的有章法的总结文」

PHPzPHPz2763일 전575

모든 응답(1)나는 대답할 것이다

  • PHP中文网

    PHP中文网2017-04-18 09:54:44

    파이썬 시간 모듈 요약(시간 및 날짜/시간)

    그런데 게시자는 이미 Google을 알고 있는데 왜 아직도 「针对这 2 个模块的有章法的总结文」
    Google 알고리즘을 믿으라고

    라고 요청하시나요?

    회신하다
    0
  • 취소회신하다