⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 date.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 4 页
字号:
    }    return names;},//>	@method		date.getShortYear()	//      Return a 2 digit year for this date.//	@group	dateFormatting//	@return		(string)	year number, padded to 2 characters//  @visibility external//<getShortYear : function () {	var year = this.getFullYear();	return (year % 100).stringify(2);},//// Date Formatters (toNormalDate(), toShortDate(), etc.)//// Date formatters are applied to date objects to convert them into strings for display.// Dates are intended to be localizable.  // For localization, a developer would typically set either the shortDateFormatter or // normalDateFormatter, as well as the inputDateFormat, and then call// "toNormalDate()" / "toShortDate()" and "parseInput()" as normal.//>	@method		date.toDateStamp()//			Return this date in the format://				<code><i>YYYYMMDD</i>T<i>HHMMSS</i>[Z]</code>//		@group	dateFormatting//		@return					(string)	formatted date string//  @visibility external//<toDateStamp : function () {	return	this.getUTCFullYear()		  + (this.getUTCMonth()+1).stringify()		  + this.getUTCDate().stringify()		  + "T"		  +	this.getUTCHours().stringify()		  + this.getUTCMinutes().stringify()		  + this.getUTCSeconds().stringify()		  + "Z";},//>	@method date.toNormalDate()// Returns the date as a formatted string using the format set up via the // <code>setNormalDisplayFormat()</code> method. Note that the default formatter for this// method is <code>"toLocaleString"</code>.// @group   dateFormatting// @param format (DateDisplayFormat) Optional Format for the date returned // @return  (string) formatted date string// @visibility external//<// This method is used by our data components such as ListGrid to display long format dates.toNormalDate : function (formatter) {            if (!formatter) formatter = this.formatter;        // fire the formatter in the scope of this date, so date is available as 'this'    if (isc.isA.Function(formatter)) {        return formatter.apply(this)    } else if (this[formatter]) {        return this[formatter]();    }},//>	@method date.toShortDate()// Returns the date as a formatted string using the format set up via the // <code>setShortDisplayFormat()</code> method.// @group   dateFormatting// @param format (DateDisplayFormat) Optional Format for the date returned // @return  (string) formatted date string// @visibility external//<toShortDate : function (formatter) {    if (!formatter) formatter = this._shortFormat;    if (isc.isA.Function(formatter)) return formatter.apply(this);    else if (isc.isA.Function(this[formatter])) return this[formatter]();},// _toShortDate()// Internal method to give us a shortDate - either DD/MM/YYYY, MM/DD/YYYY or YYYY/MM/DD.// this will be passed "MDY" / "DYM" / etc. as a format parameter._shortDateTemplate:[,,,,"/",,,,,"/",,,,null],_$MDY:"MDY",_$DMY:"DMY",_$YMD:"YMD",_$MDY:"MDY",_toShortDate : function (format) {    var template = this._shortDateTemplate,        month = this.getMonth()+1,        day = this.getDate(),        year = this.getFullYear(),        monthIndex, dayIndex, yearIndex;            if (format == this._$MDY) {        monthIndex = 0;        dayIndex = 5;        yearIndex = 10;    } else if (format == this._$DMY) {        dayIndex = 0;        monthIndex = 5;        yearIndex = 10;    } else if (format == this._$YMD) {        yearIndex = 0;        monthIndex = 5;        dayIndex = 10        // Unlikely - don't bother avoiding string alloc's for every one of these options    } else {        dayIndex = format.indexOf("D")*5;        yearIndex = format.indexOf("Y")*5;        monthIndex = format.indexOf("M")*5;    }            // Note: each number has 4 slots so it can accomodate a full year    // For month/day - if we need a leading zero, fill the first slot with it    // Use fillNumber to fill 3 slots even though we have a max of 2 digits to ensure    // the last slot gets cleared out if it was populated by a year already.    template[dayIndex] = day < 10 ? Number._lzero : null    isc._fillNumber(template, day, dayIndex+1, 3);            template[monthIndex] = month < 10 ? Number._lzero : null    isc._fillNumber(template, month, monthIndex+1, 3);                isc._fillNumber(template, this.getFullYear(), yearIndex, 4);    return template.join(isc.emptyString);},//>	@method		date.toUSShortDate()//			Return this date in the format: <code>MM/DD/YYYY</code>//		@group	dateFormatting//		@return					(string)	formatted date string//  @visibility external//<toUSShortDate : function () {    return this._toShortDate(this._$MDY);},//>	@method		date.toUSShortDateTime()//  Return this date in the format: <code>MM/DD/YYYY HH:MM</code>//   //		@group	dateFormatting//		@return					(string)	formatted date string//  @visibility external//<toUSShortDateTime : function () {    return (this.toUSShortDate() + " " +            this.getHours().stringify() + ":" +            this.getMinutes().stringify());},//>	@method		date.toEuropeanShortDate()//			Return this date in the format: <code>DD/MM/YYYY</code>//		@group	dateFormatting//		@return					(string)	formatted date string//      @visibility external//<toEuropeanShortDate : function () {    return this._toShortDate(this._$DMY);},//>	@method		date.toEuropeanShortDateTime()// Return this date in the format: <code>DD/MM/YYYY HH:MM</code>.//		@group	dateFormatting//		@return					(string)	formatted date string//      @visibility external//<toEuropeanShortDateTime : function () {    return (this.toEuropeanShortDate() + " " +            this.getHours().stringify() + ":" +            this.getMinutes().stringify());},//> @method date.toJapanShortDate()// Return the date in this format: <code>YYYY/MM/DD</code>// @group dateFormatting// @return (string) formatted date string// @visibility external//<toJapanShortDate : function () {    return this._toShortDate(this._$YMD);},//>	@method		date.toJapanShortDateTime()//			Return this date in the format: <code>YYYY/MM/DD HH:MM:SS</code>//		@group	dateFormatting//		@return					(string)	formatted date string//      @visibility external//<toJapanShortDateTime : function () {    return (this.toJapanShortDate() + " " +            this.getHours().stringify() + ":" +            this.getMinutes().stringify());},  //>	@method		date._serialize()	(A)//			Serialize this date to a string in a format that can be reinstantiated back into a date.//				<code>$$DATE$$:<i>YYYY</i>-<i>MM</i>-<i>DD</i></code>//		@group	dateFormatting//		@return					(string)	formatted date string//      @visibility internal//<_serialize : function () {    if (isc.Comm._legacyJSMode) {        // legacy mode: add $$DATE$$ that only our server-side JS parser understands        return isc.SB.concat('"' + this.toDBDate(), '"');    } else {        // any other caller: return code that would reconstruct the same Date in a JS        // interpreter                return isc.SB.concat("new Date(", this.getTime(), ")");    }},_xmlSerialize : function (name, type, namespace, prefix) {	return isc.Comm._xmlValue(name, this.toSchemaDate(),                               type || (this.logicalDate ? "date" : "datetime"),                               namespace, prefix);},toSchemaDate : function (logicalDate) {    // logical date values have no meaningful time    if (logicalDate || this.logicalDate) {        return isc.SB.concat(			this.getFullYear().stringify(4),			"-",			(this.getMonth() + 1).stringify(2), 	// getMonth() is zero-based			"-",				this.getDate().stringify(2)        );    };    // represent date time values in UTC    return isc.SB.concat(			this.getUTCFullYear().stringify(4),			"-",			(this.getUTCMonth() + 1).stringify(2), 	// getMonth() is zero-based			"-",				this.getUTCDate().stringify(2),            "T",            this.getUTCHours().stringify(2),            ":",            this.getUTCMinutes().stringify(2),            ":",            this.getUTCSeconds().stringify(2)    );},//>	@method		date.toSerializeableDate()	(A)// Return this date in 'serialized' format <code>YYYY-MM-DD HH:MM:SS</code>// @group dateFormatting// @return (String) formatted date string// @visibility external//<toSerializeableDate : function (omitTime) {    var output = isc.SB.create();    output.append(			this.getFullYear().stringify(4),			"-",			(this.getMonth() + 1).stringify(2), 	// getMonth() is zero-based			"-",				this.getDate().stringify(2)    );    if (!omitTime) output.append(            (isc.Comm.xmlSchemaMode ? "T" : " "),            this.getHours().stringify(2),            ":",            this.getMinutes().stringify(2),            ":",            this.getSeconds().stringify(2)			);    return output.toString();},//>	@method		date.toDBDate()	(A)//			Return this date in the format the database can parse as a dateTime://				<code>$$DATE$$:<i>YYYY-MM-DD HH:MM:SS</i></code>//		@group	dateFormatting////		@return					(string)	formatted date string//  @visibility internal//<// Leave this internal for nowtoDBDate : function () {	return isc.StringBuffer.concat(			"$$DATE$$:",			this.toSerializeableDate()			);},//>	@method		date.toDBDateTime()	(A)//			Return this date in the format the database can parse as a dateTime://				<code>$$DATE$$:<i>YYYY-MM-DD HH:MM:SS</i></code>//		@group	dateFormatting////		@return					(string)	formatted date string//      @visibility internal//<toDBDateTime : function () {    return this.toDBDate();       },	//>	@method		date.setFormatter()//  Set the formatter for this date object to the method name passed in.  After this call//  wherever appropriate SmartClient components will use this formatter function to return //  the date as a string.//		@group	dateFormatting//		@param	functionName	(string)	name of a date formatter method on this Date //      @visibility external//      @deprecated As of SmartClient 5.5 use the static methods//              +link{classMethod:Date.setNormalDisplayFormat} and //              +link{classMethod:Date.setShortDisplayFormat} to set default formatters for all dates//<setFormatter : function (formatter) {    this.setNormalDisplayFormat(formatter);},//>	@method	date.setLocaleStringFormatter() (A)//			Set the <code>iscToLocaleString()</code> formatter for a specific date object.//			After this call, all  <code>theDate.toLocaleString()</code>  calls will yield a string//			 in this format.////		@param	functionName	(string)	name of a dateFormatting function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -