Date.prototype.toFomatorString = function(formator)
{
var returnText = formator.toUpperCase();
if (returnText.indexOf("YYYY") > -1)
{
returnText = returnText.replace("YYYY", this.getYear());
}
if (returnText.indexOf("MM") > -1)
{
returnText = returnText.replace("MM", this.getMonth() + 1);
}
if (returnText.indexOf("DD") > -1)
{
returnText = returnText.replace("DD", this.getDate());
}
if (returnText.indexOf("HH") > -1)
{
returnText = returnText.replace("HH", this.getHours());
}
if (returnText.indexOf("MI") > -1)
{
returnText = returnText.replace("MI", this.getMinutes());
}
if (returnText.indexOf("SS") > -1)
{
returnText = returnText.replace("SS", this.getSeconds());
}
if (returnText.indexOf("SI") > -1)
{
returnText = returnText.replace("SI", this.getMilliseconds());
}
return returnText;
}
String.prototype.toDate = function()
{
var temp = this.toString();
temp = temp.replace(/-/g, "/");
var date = new Date(Date.parse(temp));
return date;
}
alert(new Date().toFomatorString("YYYY-MM-DD HH:MI:SS"));
alert("2012-05-31 23:01:34".toDate());
分享到:
相关推荐
日期转换例子,支持含各种语言的三个字母缩写...适用于数据导入数据库String类型中含英文缩写转换,网上普遍使用的String to Date 都不适用含Mon Jul 等缩写,对比API,可以实现任意格式的String 类型转换成Date类型
js string转date,js字符串转换成日期,此代码支持将datetime(年月日小时分秒格式)转换为js的Date类型,程序已调试并支持在HTML中运行、代码请见附件。
js date转String 日期字符串转换
js string转date;js构造date;js date详解;js日期处理
主要介绍了JS简单实现String转Date的方法,涉及JavaScript字符串与日期相互转换的相关技巧,需要的朋友可以参考下
js string转date
js string转date
js string转date 通过字符串格式的日期时间转换为时间类型,方便后续的业务处理,例如:时间比较,时间格式化等
js string转date
String与date的转换,在JAVA中得以实现。
Oracle中to_date格式 Data与String互转及各种用法
string 和 date类型相互转换的问题
java编程中String类型时间转化成Date类型
这意味着"2015-04-31"在stringdate.js无效,而它在 vanilla JavaScript 中的日期为 2015 年 5 月 1 日。 下面的所有函数都应应用于有效格式,否则会抛出Error 。 获取年、月、日和日 String.prototype.getYear() ...
本工具类用于String、Array和String、Date之间的转化
日期转换,long类型时间转换成string类型
String工具类:校验是否包含表情、字符串切割、过滤空白字符、过滤特殊字符(换行符、回车符、制表符) Date工具类:时间格式化转化、时间获取、时间加减(年月日时分)、数字时间校验
python 字符串和日期之间转换 StringAndDate 这里给出实现代码,直接可以使用。... ''''' String to Date(datetime) or date to string ''' def stringToDate(self,string): #example '2013-07-2
在开发应用中经常会使用到java string 转date这种不是很常见的做法,本文将以此问题提供详细解决方案,需要了解的朋友可以参考下