www.3112.net > js DAtA转换成string

js DAtA转换成string

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

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

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 str = "2010-03-22"; var val = Date.parse(str); var newDate = new Date(val); alert(newDate);

function strToDate(str) { var val = Date.parse(str); var newDate = new Date(val); return newDate; }

var ctime = $("#CaseDate").datetimebox("getValue");ctime = ctime.replace(/-/g,"/"); //为了兼容IEvar date = new Date(ctime);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...

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

字符串变成数组 就是把一个个的字符全部筛选出来 1 正则表达式 var string=“abcdedef” var obj="string".replace(/(.)(?=[^$])/g,"$1,").split(","); //字符串转化为数组 2 split var obj2 = string.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('-')...

网站地图

All rights reserved Powered by www.3112.net

copyright ©right 2010-2021。
www.3112.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com