i just made for input to DB (e.x. '1991-01-01')
Example Link :
http://jsfiddle.net/kaL0zm8r/1/
Code:
///<summary>
/// isDateOnly default : true
/// hms defualt : null (example to using "09:00:00") this parameter using when isDateOnly is false.
/// isShowUTCTimeZone default : null (example to using UTC Timezone shows like this "+09:00" ).
///</summary>
function DateToStringISO8601(date, isDateOnly, hms, isShowUTCTimeZone) {
var datestring = "";
if (date == null || date == "") {
return "";
}
if (Object.prototype.toString.call(date) !== "[object Date]") {
date = new Date(date);
//if Date is NaN, set Today
if (isNaN(date)) {
date = new Date();
}
}
datestring = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2);
if (isDateOnly != null && isDateOnly === false) {
if (hms == null || hms === "") {
datestring += "T" + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2) + ":" + ("0" + date.getSeconds()).slice(-2);// + "." + ("00" + date.getMilliseconds()).slice(-3);
}
else {
var arr = hms.split(':');
if (arr.length !== 3) {
datestring += "T" + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2) + ":" + ("0" + date.getSeconds()).slice(-2); // + "." + ("00" + date.getMilliseconds()).slice(-3);
}
else {
if ((parseInt(arr[0]) <= 24 && parseInt(arr[0]) >= 0) && (parseInt(arr[1]) <= 60 && parseInt(arr[1]) >= 0) && (parseInt(arr[2]) <= 60 && parseInt(arr[2]) >= 0)) {
datestring += "T" + ("0" + arr[0]).slice(-2) + ":" + ("0" + arr[1]).slice(-2) + ":" + ("0" + arr[2]).slice(-2);
}
else { //IF hms set wrong, set date's hms
datestring += "T" + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2) + ":" + ("0" + date.getSeconds()).slice(-2); // + "." + ("00" + date.getMilliseconds()).slice(-3);
}
}
}
}
if (isShowUTCTimeZone != null && isShowUTCTimeZone === true) {
var offset = date.getTimezoneOffset();
var hour = parseInt(offset / 60);
var min = parseInt(offset % 60);
if (hour > 0 || min > 0) { //+ means UTC -
datestring += "-" + ("0" + hour).slice(-2) + ":" + ("0" + min).slice(-2);
}
else if (hour < 0 || min < 0) { // - means UTC +
datestring += "+" + ("0" + (hour * -1)).slice(-2) + ":" + ("0" + (min * -1)).slice(-2);
}
else if (hour === 0 || min === 0) {
datestring += "Z"; //Z mean '+00:00'
}
}
return datestring;
}
Golden Nugget Casino & Hotel - MapYRO
ReplyDeleteGolden Nugget Casino & Hotel. 부산광역 출장마사지 MapYRO 전라북도 출장마사지 Hotels & Casinos. View reviews, amenities, contact details & maps. 논산 출장샵 Rating: 2.5 삼척 출장안마 · 보령 출장안마 6 votes