-3
我有一个像这样的字符串 - “05:21 PM”。如何将它转换为当前时区中的日期对象?如何将时间字符串转换为Javascript上的Date对象?
我有一个像这样的字符串 - “05:21 PM”。如何将它转换为当前时区中的日期对象?如何将时间字符串转换为Javascript上的Date对象?
.........
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');
}
HTTP:// stackoverflow.com/questions/16382266/javascript-set-time-string-to-date-object –
@Ilya Zinkevych thnx –