JSVM核心类库,收集了JAVA进行JSVM开发必用技术进行归纳,在实际项目应用中直接引用相关类库即可现实JSVM相关功能!

源代码在线查看: date.js

软件大小: 44 K
上传用户: ac3698
关键词: JSVM JAVA 核心
下载地址: 免注册下载 普通下载 VIP

相关代码

				// Description:	js.util.Date
				// Author:	Changhua.Wan
				// Version:	2004.01.26.01
				
				_package("js.util");
				
				_import("js.lang.Object");
				
				function js.util.Date(t) {
				
					js.util.Date._base.call(this);
				
					var _date = new Date();
					if (typeof(t) == "object" && t instanceof Date) t = t.getTime();
					if (typeof(t) == "number") _date = new Date(t);
				
					this.getFullYear = function() {
						return _date.getFullYear();
					}
					this.getMonth = function() {
						return _date.getMonth();
					}
					this.getDate = function() {
						return _date.getDate();
					}
					this.getHours = function() {
						return _date.getHours();
					}
					this.getMinutes = function() {
						return _date.getMinutes();
					}
					this.getSeconds = function() {
						return _date.getSeconds();
					}
					this.getTime = function() {
						return _date.getTime();
					}
					this.valueOf = function() {
						return this.getTime();
					}
					this.toString = function() {
						return js.util.Date.format(this);
					}
				
				}
				
				var _p = js.util.Date._extends("js.lang.Object");
				var _c = js.util.Date;
				
				_c.format = function(_date, _format) {
				
					var s = "YYYY-MM-DD hh:mm:ss"; // Default
					if (typeof(_format) == "string") s = _format;
					var syear = "" + _date.getFullYear();
					if (s.indexOf("YYYY") != -1) s = s.replace("YYYY", syear);
					if (s.indexOf("YY") != -1) s = s.replace("YY", syear.substring(2, 4));
					if (s.indexOf("MM") != -1) {
						var smonth = "0" + (_date.getMonth() + 1);
						smonth = smonth.substring(smonth.length - 2);
						s = s.replace("MM", smonth);
					}
					if (s.indexOf("DD") != -1) {
						var sday = "0" + _date.getDate();
						sday = sday.substring(sday.length - 2);
						s = s.replace("DD", sday);
					}
					if (s.indexOf("hh") != -1) {
						var shour = "0" + _date.getHours();
						shour = shour.substring(shour.length - 2);
						s = s.replace("hh", shour);
					}
					if (s.indexOf("mm") != -1) {
						var sminute = "0" + _date.getMinutes();
						sminute = sminute.substring(sminute.length - 2);
						s = s.replace("mm", sminute);
					}
					if (s.indexOf("ss") != -1) {
						var ssecond = "0" + _date.getSeconds();
						ssecond = ssecond.substring(ssecond.length - 2);
						s = s.replace("ss", ssecond);
					}
					return s;
				};
				
				_c.parse = function(_str) {
				
						var _date = new Date();
						if (/^(\d+)[-\/](\d{1,2})[-\/](\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/.test(_str)) {
							_date.setYear(parseInt(RegExp.$1,10));
							_date.setMonth(parseInt(RegExp.$2,10) - 1);
							_date.setDate(parseInt(RegExp.$3,10));
							_date.setHours(parseInt(RegExp.$4,10));
							_date.setMinutes(parseInt(RegExp.$5,10));
							_date.setSeconds(parseInt(RegExp.$6,10));
						} else if (/^(\d+)[-\/](\d{1,2})[-\/](\d{1,2})$/.test(_str)) {
							_date.setYear(parseInt(RegExp.$1,10));
							_date.setMonth(parseInt(RegExp.$2,10) - 1);
							_date.setDate(parseInt(RegExp.$3,10));
							_date.setHours(0);
							_date.setMinutes(0);
							_date.setSeconds(0);
						} else if (/^(\d{1,2}):(\d{1,2}):(\d{1,2})$/.test(_str)) {
							_date.setHours(parseInt(RegExp.$1,10));
							_date.setMinutes(parseInt(RegExp.$2,10));
							_date.setSeconds(parseInt(RegExp.$3,10));
						} else {
							var t = Date.parse(_str);
							if (!isNaN(t))
								_date = new Date(t);	
							_date = null;
						}
						return _date;
				}			

相关资源