大家好我是小怡,js字符串转日期,关于js字符串日期转时间戳很多人还不知道,那么现在让我们一起来看看吧!

js字符串转日期 js字符串日期转时间戳js字符串转日期 js字符串日期转时间戳


js字符串转日期 js字符串日期转时间戳


1、mth:用整数表示月份,从(1月)到11(12月)////this.Hour = dt.Hour;// //// 日期对象类库 //// /////// 说明: 兼容ASP.NET日期类型 接口: addDays(n) - 增加n天/// Example:// var d = new DateTime();// var d = new DateTime(dateObject);// var d = new DateTime(dateString);// var d = new DateTime(year, month, date, hours, minutes, seconds,ms)var CST_DATE_SPLIT = '-';var CST_DATE_TIME_SPLIT = ' ';var CST_TIME_SPLIT = ':';/ 对象: DateTime 说明: 构造 参数: year - 日期实例 year - 日期字符串 year,month,day,hour,minute,second,ms - 年,月,日,时,分,秒,毫秒/function DateTime(year, month, day, hour, minute, second, ms){var d = new Date();// 属性定义this.Month = d.getMonth();this.Day = d.getDay();this.Hour = this.Minute = this.Second = this.Millisecond = 0;// 方法定义this.toString = function(){return digi(this.Year, 4) + CST_DATE_SPLIT +digi(this.Month, 2) + CST_DATE_SPLIT +digi(this.Day, 2) + CST_DATE_TIME_SPLIT +digi(this.Hour, 2) + CST_TIME_SPLIT +digi(this.Minute,2) + CST_TIME_SPLIT +digi(this.Second,2) + CST_DATE_TIME_SPLIT +digi(this.Millisecond, 3);}this.toDateString = function(splitter){var s = '-';return digi(this.Year, 4) + ((s=='cn') ? 'u5E74' : s) +digi(this.Day, 2) + ((s=='cn') ? 'u65E5' : '');}this.toTimeString = function(splitter){var s = ':';return digi(this.Hour, 2) + ((s=='cn') ? 'u65F6' : s) +digi(this.Minute,2) + ((s=='cn') ? 'u5206' : s) +digi(this.Second,2) + ((s=='cn') ? 'u79D2' : '');}this.toDateTimeString = function(splitter){var s = ':';return digi(this.Year, 4) + ((s=='cn') ? 'u5E74' : s) +digi(this.Day, 2) + ((s=='cn') ? 'u65E5' : '') +' ' +digi(this.Hour, 2) + ((s=='cn') ? 'u65F6' : ':') +digi(this.Minute,2) + ((s=='cn') ? 'u5206' : ':') +digi(this.Second,2) + ((s=='cn') ? 'u79D2' : '');}this.clone = function(dt){this.Year = dt.Year;this.Month = dt.Month;this.Day = dt.Day;this.Minute = dt.Minute;this.Second = dt.Second;this.Millisecond = dt.Millisecond;}this.parseDate = function(date){this.Year = date.getFullYear();this.Month = (date.getMonth() + 1);this.Day = date.getDate();this.Hour = date.getHours();this.Minute = date.getMinutes();this.Second = date.getSeconds();this.Millisecond = date.getMilliseconds()}this.toDate = function(){}this.addDays = function(value){var CST_DAY_MILLISECONDS = 86400000;var vd = CST_DAY_MILLISECONDS value;d.setMilliseconds(d.getMilliseconds() + vd);this.parseDate(d);}this.addYearsthis.addMonths = function(value){// to be do...}this.addMonths = function(value){// to be do...}this.addHours = function(value){this.addDays(value/24);}this.addMinutes = function(value){this.addHours(value/60);}this.addSeconds = function(value){this.addMinutes(value/60);}this.parseString = function(src){var o = Date.parseDate(src);if (o == null || o.getType == null || o.getType() != "Date"){return null;}else{this.parseDate(o);}}// 实例化var args = arguments;if (args.length == 1){var o = args[0];if(typeof(o) == "string"){o = Date.parseDate(o);}if (o == null || o.getType == null || o.getType() != "Date"){return null;}else{this.parseDate(o);}}else if (args.length >= 3){this.Year = parseInt(args[0]);this.Month = parseInt(args[1]);this.Day = parseInt(args[2]);}if (args.length >= 4){this.Hour = parseInt(args[3]);}if (args.length >= 5){this.Minute= parseInt(args[4]);}if (args.length >= 6){this.Second= parseInt(args[5]);}if (args.length >= 7){this.Millisecond= parseInt(args[6]);}}function digi(v, c){v = v + "";var n = "0000";if(v.length return n.substr(0, c-v.length) + v;return v;}DateTime.prototype = new Object();DateTime.getType = function(){return "DateTime";}/ 函数: (静态)parseXml 说明: 从XML字符串解释 参数: xml - XML 描述 示例: 2005-01-01/DateTime.parseXml = function(xml, binary){var doc = XmlDocument();doc.loadXML(xml);return new DateTime(doc.text);//var xml = "" + s1 + "";}Js代码/ js 对date加减/Date.prototype.Format = function(fmt) {// author: meizzvar o = {"M+" : this.getMonth() + 1, // 月份"d+" : this.getDate(), // 日"h+" : this.getHours(), // 小时"m+" : this.getMinutes(), // 分"s+" : this.getSeconds(), // 秒"q+" : Math.floor((this.getMonth() + 3) / 3), // 季度"S" : this.getMilliseconds()// 毫秒if (/(y+)/.test(fmt))fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4- RegExp.$1.length));for (var k in o)if (new RegExp("(" + k + ")").test(fmt))fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1)? (o[k]): (("00" + o[k]).substr(("" + o[k]).length)));return fmt;}Date.prototype.addDays = function(d) {this.setDate(this.getDate() + d);Date.prototype.addWeeks = function(w) {this.addDays(w 7);Date.prototype.addMonths = function(m) {var d = this.getDate();this.setMonth(this.getMonth() + m);if (this.getDate() this.setDate(0);Date.prototype.addYears = function(y) {var m = this.getMonth();this.setFullYear(this.getFullYear() + y);if (m this.setDate(0);}};Date.prototype.toDateString = function(formatStr) {var date = this;var timeValues = function() {timeValues.prototype = {year : function() {if (formatStr.indexOf("yyyy") >= 0) {return date.getYear();} else {return date.getYear().toString().substr(2);}},elseTime : function(val, formatVal) {return formatVal >= 0 ? (val },month : function() {return this.elseTime(date.getMonth() + 1, formatStr.indexOf("MM"));},day : function() {return this.elseTime(date.getDate(), formatStr.indexOf("dd"));},hour : function() {return this.elseTime(date.getHours(), formatStr.indexOf("hh"));},minute : function() {return this.elseTime(date.getMinutes(), formatStr.indexOf("mm"));},return this.elseTime(date.getSeconds(), formatStr.indexOf("ss"));}}var tV = new timeValues();var replaceStr = {year : ["yyyy", "yy"],month : ["MM", "M"],day : ["dd", "d"],hour : ["hh", "h"],minute : ["mm", "m"],second : ["ss", "s"]for (var key in replaceStr) {formatStr = formatStr.replace(replaceStr[key][0], eval("tV." + key+ "()"));formatStr = formatStr.replace(replaceStr[key][1], eval("tV." + key+ "()"));}return formatStr;}function formatStrDate(date) {var str = date.toDateString("yyyy-MM-dd hh:mm:ss");return str.replace("00:00:00", "10:00:00");}return str;}var date = new Date();date.addDays(-3);console.(date.toDateString("yyyy-MM-dd hh:mm:ss"));import ja.util.Date;long time = Calendar.getInstance().getTimeInMillis();Date newDate = new Date(time + 45l 24l 3600l 1000l);//当前毫秒数 + 45天24小时3600秒1000毫秒,这个地方的数字注意结尾要加字母l。

2、System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(newDate));这个newDate就是你要的日期。

3、jascript 时间日期处理相加,减作方法jsvar d = new Date("2008/04/15");d.setMonth(d.getMonth() + 1 + 1);//加一个月,同理,可以加一天:getDate()+1,加一年:getYear()+1alert(d+"月后是"+d.getFullYear()+"-"+d.getMonth()+"-"+d.getDate());//-->var dat=new Date();。

本文到这结束,希望上面文章对大家有所帮助。