参考技术A<script> var d = new Date(); var year = d.getFullYear(); var month = d.getMonth() + 1; var date = d.getDate(); var hours = d.getHours(); var min = d.getMinutes(); var seconds = d.getSeconds();
var localDate = year+"-"+month+"-"+date + " " + hours + ":" + min + ":" + seconds;
console.log(localDate); //结果 2018-5-23 12:53:32
</script>
python utc和当地时间之间的日期时间转换
"""
Transform utc time system to local time
"""
def utc2local(dateutc):
from datetime import datetime
from dateutil import tz
# setup
from_zone = tz.tzutc()
to_zone = tz.tzlocal()
# transform
try:
# if dateutc is not a string is transformed previously
utc = datetime.strptime(dateutc,"%Y-%m-%d %H:%M:%S")
except:
utc = dateutc
utc = utc.replace(tzinfo=from_zone)
datelocal = utc.astimezone(to_zone)
# return datetime object
return datetime(datelocal.year,datelocal.month,datelocal.day,datelocal.hour,datelocal.minute,datelocal.second)
"""
Transform utc time system to local time
"""
def local2utc(datelocal):
from datetime import datetime
from dateutil import tz
# setup
to_zone = tz.tzutc()
from_zone = tz.tzlocal()
# transform
try:
# if dateutc is not a string is transformed previously
local = datetime.strptime(datelocal,"%Y-%m-%d %H:%M:%S")
except:
local = datelocal
local = local.replace(tzinfo=from_zone)
dateutc = local.astimezone(to_zone)
# return datetime object
return datetime(dateutc.year,dateutc.month,dateutc.day,dateutc.hour,dateutc.minute,dateutc.second)