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.


沒有留言:

張貼留言

[Linux 常見問題] What's the best way to send a signal to all members of a process group?

Source From  Here   Question   I want to  kill a whole process tree.  What is the best way to do this using any common scripting languages? ...