python、js 时间日期模块time

python

参考链接:https://www.runoob.com/python/python-date-time.html

时间戳

>>> print(time.time())#别输成time.time
1556983197.7285311

格式化

>>> print(time.strftime("%Y-%m-%d",time.localtime()))
2019-05-04
#还可以
# 格式化成2016-03-20 11:45:39形式
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 

  

js

参考链接:http://www.w3school.com.cn/js/js_obj_date.asp

更全的:http://www.w3school.com.cn/jsref/jsref_obj_date.asp

将时间戳转换为常见日期格式

<script type="text/javascript">
var d=new Date();
d.setTime(1556249218239.59)
document.write("今天日期:" + d.toLocaleDateString());
</script>

//输出

从 1970/01/01 至今已过去 1556249218239 毫秒今天日期:2019/4/26

  

  

  

猜你喜欢

转载自www.cnblogs.com/Gaoqiking/p/10810419.html