cfnr.net
当前位置:首页 >> js DAtE string >>

js DAtE 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 );

JS原生有个方法可以把对象转换成字符串类型,如果需要把日期转换成字符串,代码可以这样写: var data = new Date;var string = data.toLocaleString();alert(typeof(string));输出就会发现在是个string类型了。

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...

var str = "2010-08-01";// 转换日期格式str = str.replace(/-/g, '/'); // "2010/08/01";// 创建日期对象var date = new Date(str);// 加一天date.setDate(date.getDate() + 1);

var now = new Date(); var year = now.getFullYear(); var month =(now.getMonth() + 1).toString(); var day = (now.getDate()).toString(); if (month.length == 1) { month = "0" + month; } if (day.length == 1) { day = "0" + day; } va...

var ctime = $("#CaseDate").datetimebox("getValue");ctime = ctime.replace(/-/g,"/"); //为了兼容IEvar date = new Date(ctime);date就是你要的日期格式

var d = new Date(); alert(d.getYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()); alert(d.toString()); alert(d.toLocaleString());

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

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