我有一个包含纪元时间的变量。我想以 HHMM 格式显示时间。
这是我的代码;
function epoch_time_to_date_obj(epoch_time)
{
var utcSeconds = epoch_time;
var d = new Date(0);
d.setUTCSeconds(utcSeconds);
return d;
}
let epoch_time = 1234567890;
let date_obj = epoch_time_to_date_obj(epoch_time);
我想从 date_obj
中提取 HHMM 时间信息,并以香港时间的 HHMM 格式显示时间。
我正在使用 node.js v6
最佳答案
let epoch_time = 1234567890 * 1000;
var date_obj = new Date(epoch_time);
const hrs = date_obj.getHours();
const mins = date_obj.getMinutes();
let hhmm = (hrs < 10 ? "0" + hrs : hrs) + ":" + (mins < 10 ? "0" + mins : mins);
alert(hhmm);
关于javascript - 在 javascript 中将纪元时间显示为 HHMM 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41015272/