ホームページ >ウェブフロントエンド >jsチュートリアル >JS_javascript スキルで時刻の書式設定を実装する方法の概要
function getSmpFormatNowDate(isFull) {
return getSmpFormatDate(new Date(), isFull);
}
/**
* Convert long value to date string
* @param l long value
* @param isFull Whether it is complete date data,
* When it is true, the format is such as "2000-03-05 01:05:04"
* When it is false, the format is like "2000-03-05"
* @return a date string that meets the requirements
*/
function getSmpFormatDateByLong(l, isFull) {
return getSmpFormatDate(new Date(l), isFull);
}
/**
*Convert long value to date string
* @param l long value
* @param pattern format string, for example: yyyy-MM-dd hh:mm:ss
* @return conforms Requested date string
*/
function getFormatDateByLong(l, pattern) {
return getFormatDate(new Date(l), pattern);
}
/**
*Convert date object to date string
* @param l long value
* @param pattern format string, for example: yyyy-MM-dd hh:mm:ss
* @return conforms Requested date string
*/
function getFormatDate(date, pattern) {
if (date == undefined) {
date = new Date();
}
if (pattern == undefined) {
pattern = "yyyy-MM-dd hh:mm:ss";
}
return date.format(pattern);
}
//alert(getSmpFormatDate(new Date(1279849429000), true));
//alert(getSmpFormatDate(new Date(1279849429000),false));
//alert(getSmpFormatDateByLong(1279829423000, true));
//alert(getSmpFormatDateByLong(1279829423000,false));
//alert(getFormatDateByLong(1279829423000, "yyyy-MM"));
//alert(getFormatDate(new Date(1279829423000), "yy-MM"));
//alert(getFormatDateByLong(1279849429000, "yyyy-MM hh:mm"));