2018年4月30日 星期一

[ Python 常見問題 ] Converting Epoch time into the datetime

Source From Here 
Question 
I am getting a response from the rest is an Epoch time format like: 
  1. start_time = 1234566  
  2. end_time = 1234578  
I want to convert that epoch seconds to be transformed into below format (Check strftime): 
2012-09-12 21:00:00

How-To 
To convert your time value (float or int) to a formatted string, use: 
>>> time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(1347517370)) // For my local TimeZone as UTC+8 
'2012-09-13 14:22:50' 

>>> time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(1347517370)) // The time with TimeZone as UTC+0 
'2012-09-13 06:22:50'

Reference: 
* time.localtime([secs]): 
Like gmtime() but converts to local time. If secs is not provided or None, the current time as returned by time() is used. The dst flag is set to 1 when DST applies to the given time.


沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...