datelib.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:protoc-gen-lua-bin 作者: u0u0 项目源码 文件源码
def DatetimeToUTCMicros(date):
  """Converts a datetime object to microseconds since the epoch in UTC.

  Args:
    date: A datetime to convert.
  Returns:
    The number of microseconds since the epoch, in UTC, represented by the input
    datetime.
  """
  # Using this guide: http://wiki.python.org/moin/WorkingWithTime
  # And this conversion guide: http://docs.python.org/library/time.html

  # Turn the date parameter into a tuple (struct_time) that can then be
  # manipulated into a long value of seconds.  During the conversion from
  # struct_time to long, the source date in UTC, and so it follows that the
  # correct transformation is calendar.timegm()
  micros = calendar.timegm(date.utctimetuple()) * _MICROSECONDS_PER_SECOND
  return micros + date.microsecond
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号