简体   繁体   English

将纪元时间转换为人类可读时间

[英]Convert Epoch Time to Human Readable time

Does anyone know if there is a javascript ONLY way to convert an epoch number into a human readable date? 有没有人知道是否只有javascript方法将时代号转换为人类可读日期? I have this code, but I keep getting back a number. 我有这个代码,但我一直在找回一个号码。 I want to convert this number into a human readable date if possible (ex: 2012/3/23). 如果可能的话,我想将此数字转换为人类可读的日期(例如:2012/3/23)。

This was a resource I used for my code... http://www.epochconverter.com/programming/ 这是我用于代码的资源... http://www.epochconverter.com/programming/

Play with my jsfiddle ... http://jsfiddle.net/4FSEp/ 和我的jsfiddle一起玩...... http://jsfiddle.net/4FSEp/

var myDate=new Date();

myDate = myDate.setFullYear(2012,3,23);

document.write(myDate);

document.write(myDate.toGMTString()+"<br>"+myDate.toLocaleString());

Change 更改

myDate = myDate.setFullYear(2012, 3, 23);

to

myDate.setFullYear(2012, 2, 23);

( edit — wow I didn't know setFullYear() could also take a month and a day-of-month :-) 编辑 - 哇我不知道setFullYear()也可能需要一个月和一个月的日子:-)

Those routines modify the date object, so there's no need to re-assign. 这些例程修改了日期对象,因此无需重新分配。

edit — if you have a date, and you want to move it to five days ahead of that date, you'd do this: 编辑 - 如果您有一个日期,并且您希望将其移动到该日期之前的五天,您可以这样做:

myDate.setDate( myDate.getDate() + 5 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用特定时区将纪元时间转换为人类可读的时间 - Convert Epoch time to human readable with specific timezone 使用 Moment.js 将 Unix 纪元时间转换为人类可读的时间 - Use Moment.js to convert Unix epoch time to human readable time 使用 Moment.js 将人类可读时间转换为 Unix 纪元时间 - Use Moment.js to convert human readable time to Unix epoch time 如何将 JSON 时间转换为可读的人类格式? - How to convert JSON time into readable human format? 将纪元时间转换为JavaScript中的可读格式 - Convert epoch time to readable format in javascript 在将数据发送到 Google 表格之前,如何将 Apps 脚本中的 API JSON 响应转换为人类可读的纪元时间(以秒为单位)? - How can I convert epoch time in seconds to human readable from API JSON response in Apps Script before sending the data to Google Sheets? 可读的时间解析器 - Human readable time parser 将 Django rest Api 日期时间值转换为人类可读的值 - Convert Django rest Api date time value to human readable value 将人类可读持续时间转换为时间格式SQL SERVER 2014 - Convert human readable duration to Time Format SQL SERVER 2014 JavsScript:如何将UTC时间戳转换为人类可读的时间? - JavsScript: How to convert a UTC timestamp to human readable time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM