我想從time
值中減去午餐時間,但我似乎無法使其工作。以下是我使用的代碼:從Javascript中的時間字段中減去持續時間
// get the values of the fields
var sStart = this.getField("StartTimeMonday").value;
var sEnd = this.getField("FinishTimeMonday").value;
// clear field as a default action
event.value = "";
// compute only if we have values
if (sStart != "" && sEnd != "") {
// add a formatted date value to the time field values
sStart = "1-Jan-1970 " + sStart;
sEnd = "1-Jan-1970 " + sEnd;
// convert the date time strings to date object
var oStart = util.scand("d-mmm-yyyy h:MM tt", sStart);
var oEnd = util.scand("d-mmm-yyyy h:MM tt", sEnd);
// convert date object to milliseconds since 1-Jan-1970
var nStart = oStart.getTime();
var nEnd = oEnd.getTime();
// compute the difference in milliseconds
var nDiff = nEnd - nStart;
// convert to seconds
var nSeconds = Math.floor(nDiff/1000);
// compute the whole hours from the minutes
var nHrs = Math.floor(nSeconds/3600);
// compute the remaining minutes
var nMins = (nSeconds/60) % 60;
// set field value string to formatted time string
event.value = nHrs + ":" + util.printf("%,202.0f", nMins);
}
該文件包含了午餐時間的持續時間time
值(在我的時間表)字段顯示之前從最終值中減去。例如,在下面的示例中,最終值應爲11:30
。
我怎樣才能做到這一點?
確實24小時格式支持'AM/PM'? –
@AnikIslamAbhi號'MealTimeMonday'採用'HH:MM'格式。 – Bababarghi
因此,如果是24小時格式,爲什麼在截圖中有AM/PM? – epascarello