Python 和js时间处理

时间:2021-07-14 22:07:29

仅作笔记


Python

======
import time
import datetime

date = datetime.datetime(*args)
time.mktime(date.timetuple())

time.time()
time.gmtime()
time.strftime()


Javascript
=========
date = new Date(1378134893)
date = new Date('2013-9-2 23:15')


date.getTime()
date.getTimezoneOffset() * 60000




更具北京时间计算美国东部时区、太平洋时区时间
zone in ['GMT-#00', 'GMT-8#00']
function getZoneDate(date, zone) {                                               
if (date == null)
return '';
if (zone == 'GMT-5#00')
zone = -5;
else if (zone == 'GMT-8#00')
zone = -8;
var localtime = date.getTime(),
utc = localtime + date.getTimezoneOffset() * 60000,
zone_date_time = zone * 60 * 60000 + utc,
zone_date = new Date(zone_date_time);
var tmp_zone_date = new Date(zone_date_time);
tmp_zone_date.setDate(1);
// between 2:00 of second sunday of march and 2:00 first sunday
if ((zone_date.getMonth() > 2 && zone_date.getMonth() < 10) || ((14 - tmp_zone_date.getDay() <= zone_date.getDate() && ((zone_date.getMonth() == 2 && zone_date.getHours() >= 2) || (zone_date.getMonth() == 10 && zone_date.getHours() <= 2))))){
zone_date_time += 60 * 60000;
zone_date = new Date(zone_date_time);
}
var time = zone_date.getFullYear() + '-' + (zone_date.getMonth() + 1) + '-' + zone_date.getDate() + " " + zone_date.getHours() + ":" + zone_date.getMinutes();
return time;
}