我有一个将 SQL 日期时间戳转换为格式化时间的函数。它在 iOS 设备上看起来不错,但在 Android 设备上显示为军用时间。我怎样才能让它在 android 设备上返回 toLocaleTimeString() 而不是军事时间?
function fromDateString(str) {
var res = str.match(/\/Date\((\d+)(?:([+-])(\d\d)(\d\d))?\)\//);
if (res == null)
return new Date(NaN); // or something that indicates it was not a DateString
var time = parseInt(res[1], 10);
if (res[2] && res[3] && res[4]) {
var dir = res[2] == "+" ? -1 : 1,
h = parseInt(res[3], 10),
m = parseInt(res[4], 10);
time += dir * (h*60+m) * 60000;
}
return formatdate.toLocaleTimeString();
}