simpledateformat

时间:2026-04-17 21:23:22编辑:莆田seo君

jquery里,怎么格式化时间

/**
* 时间对象的格式化;
*/
Date.prototype.format = function(format) {
/*
* 使用例子:format="yyyy-MM-dd hh:mm:ss";
*/
var o = {
"M+" : this.getMonth() + 1, // month
"d+" : this.getDate(), // day
"h+" : this.getHours(), // hour
"m+" : this.getMinutes(), // minute
"s+" : this.getSeconds(), // second
"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
"S" : this.getMilliseconds()
// millisecond
}

if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4
- RegExp.$1.length));
}

for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1
? o[k]
: ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
}


java怎么将date类型转换成datetime类型

日期内容的字符串转化为DateTime类型,将字符类型的日期转化为DateTime类型主要有以下方法:方法一:Convert.ToDateTime(string)string格式有要求,必须是yyyy-MM-dd hh:mm:ss方法二:Convert.ToDateTime(string, IFormatProvider)DateTime dt;DateTimeFormatInfo dtFormat = new System.GlobalizationDateTimeFormatInfo();dtFormat.ShortDatePattern = "yyyy/MM/dd";dt = Convert.ToDateTime("2011/05/26", dtFormat);方法三:DateTime.ParseExact()string dateString = "20110526";DateTime dt = DateTime.ParseExact(dateString, "yyyyMMdd",System.Globalization.CultureInfo.CurrentCulture);DateTime dt = DateTime.ParseExact(dateString, "yyyyMMdd",System.Globalization.CultureInfo.InvariantCulture);

上一篇:电脑系统怎么装

下一篇:没有了