Python 的 time 和 datetime 几个 API 函数的全称问题?
PHPz
PHPz 2017-04-18 09:52:44
0
1
543

2016/11/7

问题

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

注释中附我的的猜想

真正问题是:

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

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

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

是怎么解决的?

  • 1

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.
  • 2

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.
  • 3

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).
  • 4

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 个模块的有章法的总结文」

PHPz
PHPz

学习是最好的投资!

répondre à tous(1)
洪涛

Résumé du module de temps python (heure et dateheure)

D'ailleurs, l'affiche connaît déjà Google, pourquoi demandez-vous encore 「针对这 2 个模块的有章法的总结文」
de faire confiance à l'algorithme de Google

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!