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

📄 time.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*
 * Isomorphic SmartClient
 * Version 6.5 (2008-04-30)
 * Copyright(c) 1998-2007 Isomorphic Software, Inc. All rights reserved.
 * "SmartClient" is a trademark of Isomorphic Software, Inc.
 *
 * licensing@smartclient.com
 *
 * http://smartclient.com/license
 */
//> @class  Time// Class with helper methods for converting dates to and from formatted time strings.//  @treeLocation Client Reference/System// @visibility external//<isc.ClassFactory.defineClass("Time");isc.Time.addClassProperties({    //> @classAttr  Time.UTCHoursOffset (number : 0 : IRA)    // Time data is stored in Date type objects.     // In order to have times display consistently across browsers all times are stored as    // UTC time by default.    // This property may be modified to change the timezone used to store times - for example    // if you have legacy server data with date-time data in PST and you need it to be     // consistently stored and updated in this format, modify this property to be the number    // of hours offset from UTC.    // @visibility external    //<    UTCHoursOffset:0,    //>	@classAttr	isc.Time._timeExpressions (Array : [..] : IRA)	// List of regular expressions to parse a time string	//		@group	parsing	//<	_timeExpressions : [							/^\s*(\d?\d)\s*[: ]\s*(\d?\d)\s*[: ]\s*(\d?\d)?\s*([AaPp][Mm]?)?\s*$/,			/^\s*(\d?\d)\s*[: ]\s*(\d?\d)(\s*)([AaPp][Mm]?)?\s*$/,			/^\s*(\d\d)(\d\d)(\d\d)?\s*([AaPp][Mm]?)?\s*$/,			/^\s*(\d)(\d\d)(\d\d)?\s*([AaPp][Mm]?)?\s*$/,			/^\s*(\d\d?)(\s)?(\s*)([AaPp][Mm]?)?\s*$/		],    //> @type   timeFormatter    // String designating a standard time formatter for displaying the times associated with     // dates strings.    // @value   toTime    //  String will display with seconds and am/pm indicator:<code>[H]H:MM:SS am|pm</code>. <br>    //  Example: <code>3:25:15 pm</code>    // @value  to24HourTime    //  String will display with seconds in 24 hour time: <code>[H]H:MM:SS</code>. <br>    //  Example: <code>15:25:15</code>    // @value  toPaddedTime    //  String will display with seconds, with a 2 digit hour and am/pm indicator:     //  <code>HH:MM:SS am|pm</code> <br>    //  Example: <code>03:25:15 pm</code>    // @value  toPadded24HourTime    //  String will display with seconds, with a 2 digit hour in 24 hour format:     //  <code>HH:MM:SS</code> <br>    //  Examples: <code>15:25:15</code>, <code>03:16:45</code>    // @value toShortTime    //  String will have no seconds and be in 12 hour format:<code>[H]H:MM am|pm</code><br>    //  Example: <code>3:25 pm</code>    // @value toShort24HourTime    //  String will have no seconds and be in 24 hour format: <code>[H]H:MM</code><br>    //  Example:<code>15:25</code>    // @value toShortPaddedTime    //  String will have no seconds and will display a 2 digit hour, in 12 hour clock format:    //  <code>HH:MM am|pm</code><br>    //  Exmaple: <code>03:25 pm</code>    // @value toShortPadded24HourTime    //  String will have no seconds and will display with a 2 digit hour in 24 hour clock format:    // <code>HH:MM</code><br>    // Examples: <code>15:25</code>, <code>03:16</code>    //    // @visibility external    //<    // To simplify parsing / formatting, map valid formatter names to the details of the format    formatterMap:{        toTime:{showSeconds:true, padded:false, show24:false},        to24HourTime:{showSeconds:true, padded:false, show24:true},        toPaddedTime:{showSeconds:true, padded:true, show24:false},        toPadded24HourTime:{showSeconds:true, padded:true, show24:true},                toShortTime:{showSeconds:false, padded:false, show24:false},        toShort24HourTime:{showSeconds:false, padded:false, show24:true},        toShortPaddedTime:{showSeconds:false, padded:true, show24:false},        toShortPadded24HourTime:{showSeconds:false, padded:true, show24:true}    },                //> @classAttr Time.displayFormat  (timeFormatter|function : "toTime" : RWA)    // Standard formatter to be used when converting a date to a time-string via +link{Time.toTime()}    // @setter Time.setNormalDisplayFormat()    // @visibility external    //<    displayFormat:"toTime",    //> @classAttr Time.shortDisplayFormat  (timeFormatter|function : "toShortTime" : RWA)    // Standard formatter to be used when converting a date to a time-string via +link{Time.toShortTime()}    // @setter Time.setShortDisplayFormat()    // @visibility external    //<    shortDisplayFormat:"toShortTime",        //> @classAttr Time.AMIndicator (string : " am" : RWA)    // String appended to times to indicate am (when not using 24 hour format).    // @visibility external    // @group i18nMessages    //<    AMIndicator:" am",    //> @classAttr Time.PMIndicator (string : " pm" : RWA)    // String appended to times to indicate am (when not using 24 hour format).    // @visibility external    // @group i18nMessages    //<    PMIndicator:" pm"});isc.Time.addClassMethods({    //> @classMethod Time.toTime()    // Given a date object, return the time associated with the date as a string.    // If no formatter is passed, use the standard formatter set up via +link{Time.setNormalDisplayFormat()}    // @param date (Date) Date to convert to a time string.    // @param [formatter] (timeFormatter|function) Optional custom formatter to use. Will accept    //  a function (which will be passed a pointer to the date to perform the conversion), or    //  a string designating a standard formatter    // @visibility external    //<    toTime : function (date, formatter) {        return this.format(date, formatter, false);    },        //> @classMethod Time.toShortTime()    // Given a date object, return the time associated with the date as a short string.    // If no formatter is passed, use the standard formatter set up via +link{Time.setShortDisplayFormat()}    // @param date (Date) Date to convert to a time string.    // @param [formatter] (timeFormatter|function) Optional custom formatter to use. Will accept    //  a function (which will be passed a pointer to the Date to format), or    //  a string designating a standard formatter    // @visibility external    //<        toShortTime : function (date, formatter) {        return this.format(date, formatter, true);    },    // Given a date return a formatted time string    _$timeTemplate:[null, ":", null, ":"],    _$shortTimeTemplate:[null, ":"],    format : function (date, formatter, shortFormat) {        // If we're passed a random object (most likely null or a string), just return it        if (!isc.isA.Date(date)) return date;        var originalFormatter = formatter;        // Sanity check - don't allow unexpected things passed in as a formatter to give us        // odd results        if (!formatter && !isc.isA.String(formatter) && !isc.isA.Function(formatter)) {            formatter = shortFormat ? this.shortDisplayFormat : this.displayFormat;        }        // Support passing in a completely arbitrary formatter function        if (isc.isA.Function(formatter)) return formatter(date);                if (isc.isA.String(formatter)) formatter = this.formatterMap[formatter];                if (!isc.isAn.Object(formatter)) {            this.logWarn("Invalid time formatter:" + originalFormatter + " - using 'toTime'");            formatter = this.formatterMap.toTime;        }        var showSeconds = formatter.showSeconds,            padded = formatter.padded,            show24 = formatter.show24;                    var hour = date.getUTCHours();

⌨️ 快捷键说明

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