fkjj.net
当前位置:首页 >> JS中如何把DAtE类型转化为String,如何把String转... >>

JS中如何把DAtE类型转化为String,如何把String转...

date转String: var now=new Date();var str=now.toString();String转date: var dt = new Date("2015/5/10 10:10:10");

var str = "2010-03-22"; var val = Date.parse(str); var newDate = new Date(val); alert(newDate);

var str ='2012-08-12 23:13:15'; str = str.replace(/-/g,"/"); var date = new Date(str );

var d = '2015/02/02 14:26:00', date = new Date(d); alert(date);

1、比较常用的方法,但繁琐,参考如下: 主要使用Date的构造方法:Date(int year , int month , int day) var str1 = "2009-8-9"; var arr1 = str1.split("-"); var date1 = new Date(arr1[0],parseInt(arr1[1])-1,arr1[2]); var str2 = "2009-8...

1.比较常用的方法,但繁琐: 主要使用Date的构造方法:Date(int year , int month , int day) Java代码 var str1 = "2009-8-9"; var arr1 = str1.split("-"); var date1 = new Date(arr1[0],parseInt(arr1[1])-1,arr1[2]); var str2 = "2009-8-4...

var str = "2010-03-22"; var val = Date.parse(str); var newDate = new Date(val); alert(newDate);

在js里面怎么把时间类型转换成字符串 方法一: var temper="2009-6-28 15:23" var dt = new Date(temper.replace(/-/,"/")) alert(dt) 方法二: function ConvertDateFromString(dateString) { if (dateString) { var arr1 = dateString.split("...

方法一: var temper="2009-6-28 15:23" var dt = new Date(temper.replace(/-/,"/")) alert(dt) 方法二: function ConvertDateFromString(dateString) { if (dateString) { var arr1 = dateString.split(" "); var sdate = arr1[0].split('-')...

方法一: //字符串转日期格式,strDate要转为日期格式的字符串 function getDate(strDate){ var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/, function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')'); return da...

网站首页 | 网站地图
All rights reserved Powered by www.fkjj.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com