当前位置: 编程技术>.net/c#/asp.net
C#Js时间格式化问题简单实例
来源: 互联网 发布时间:2014-10-23
本文导语: C# 后台: 代码如下:.ToString("dd-MMM-yyyy", System.Globalization. DateTimeFormatInfo.InvariantInfo) eg : 29-Aug-2013 Js 前台: 代码如下:monName = new Array( "Jan", "Feb" , "Mar", "Apr", "May" , "Jun", "Jul", "Aug" , "Sept", "Oct", "Nov" , "Dec") Date.prototype.format = funct...
C# 后台:
代码如下:
.ToString("dd-MMM-yyyy", System.Globalization. DateTimeFormatInfo.InvariantInfo) eg : 29-Aug-2013
Js 前台:
代码如下:
monName = new Array( "Jan", "Feb" , "Mar", "Apr", "May" , "Jun", "Jul", "Aug" , "Sept", "Oct", "Nov" , "Dec")
Date.prototype.format = function (format) {
if (!format) {
format = "yyyy-MM-dd hh:mm:ss";
}
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, ( this.getFullYear() + "" ).substr(4 - RegExp.$1.length));
}
if (/(M+)/.test(format)) {
format = format.replace(RegExp.$1, (monName[ this.getMonth()] + "" ).substr(3 - RegExp.$1.length));
}
if (/(d+)/.test(format)) {
format = format.replace(RegExp.$1, ( "00" + this .getDate() + "").substr(( "" + this .getDate()).length));
}
return format;
};
function formatJsonDate(str) {
if (str != null &&str!='') {
return (new Date(parseInt(str.substring(str.indexOf( '(') + 1, str.indexOf(')' ))))).format("dd-MMM-yyyy");
}
else {
return '' ;
}