我有一个这样的字符串 - " 05:21 PM" 。如何将其转换为当前时区的日期对象?
答案 0 :(得分:0)
.........
https://www.w3schools.com/jsref/jsref_sethours.asp
var d = new Date();
d.setHours(15);
d.setMinutes(15);
toLocalTime(d.getTime())
.........
/**
* Converts CDT time to your browser local time.
* @param time
* @returns
*/
function toLocalTime(time) {
if (time <= 0)
return '';
var m = moment.tz(time, 'America/Chicago'); //CDT
var tz = jstz.determine(); // Determines the time zone of the browser client
m.tz(tz.name()); // Convert CDT to local time
return m.format('HH:mm:ss');
}