亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > JavaScript > 正文

基于jQuery的時間戳與日期間的轉化

2019-11-19 11:18:08
字體:
來源:轉載
供稿:網友

本文實例為大家分享了jQuery時間戳與日期間的轉化代碼,供大家參考,具體內容如下

背景:

需求如圖:

 直接上代碼,所有的內容都在注釋里:

/** * 格式化時間:補0操作 * */function supplement(num){  if(parseInt(num) < 10){    num = '0'+num;  }  return num;}; /** * 格式化時間:拓展jquery的全局變量 * */$.extend({  JTime:{    //當前時間戳 秒:如果要毫秒就不除以1000    newTime: function(){      //本地時間然后在轉為時間戳,沒有時區區別 == Date.now()      return Date.parse(new Date())/1000;    },    //日期格式(YY-mm-dd HH:MM:SS)轉時間戳(秒)    DateToTamp: function(oString) {      var f = oString.split(' ', 2);      var d = (f[0] ? f[0] : '').split('-', 3);      var t = (f[1] ? f[1] : '').split(':', 3);      //使用Date的構造函數,實力化并解析      return (new Date(        parseInt(d[0], 10) || null,        (parseInt(d[1], 10) || 1) - 1,        parseInt(d[2], 10) || null,        parseInt(t[0], 10) || null,        parseInt(t[1], 10) || null,        parseInt(t[2], 10) || null      )).getTime() / 1000;    },    //時間戳(秒)轉日期時間格式(YY-mm-dd [HH:MM:SS]):有條件的轉(時間戳, 是否解析時間,時區:中國=8)    TampToDate: function(unixTime, isFull, timeZone) {      //時區處理      if (typeof (timeZone) === 'number'){        unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;      }      var time = new Date(unixTime * 1000);      var ymdhis = "";      ymdhis += time.getUTCFullYear() + "-";      ymdhis += (time.getUTCMonth()+1) + "-";      ymdhis += time.getUTCDate();      //需要完整的就設置true      if (isFull === true){        ymdhis += " " + time.getUTCHours() + ":";        ymdhis += time.getUTCMinutes() + ":";        ymdhis += time.getUTCSeconds();      }      return ymdhis;    },    //時間戳(毫秒)轉日期時間格式    TampToDatetime: function (str) {      var oDate = new Date(str),        oYear = oDate.getFullYear(),        oMonth = oDate.getMonth()+1,        oDay = oDate.getDate(),        oHour = oDate.getHours(),        oMin = oDate.getMinutes(),        oSen = oDate.getSeconds(),        oTime = oYear +'-'+ supplement(oMonth) +'-'+ supplement(oDay) +' '+ supplement(oHour) +':'+ supplement(oMin) +':'+supplement(oSen); //按格式拼接時間      return oTime;    }  }});

原生的api:

interface Date {  /** Returns a string representation of a date. The format of the string depends on the locale. */  toString(): string;  /** Returns a date as a string value. */  toDateString(): string;  /** Returns a time as a string value. */  toTimeString(): string;  /** Returns a value as a string value appropriate to the host environment's current locale. */  toLocaleString(): string;  /** Returns a date as a string value appropriate to the host environment's current locale. */  toLocaleDateString(): string;  /** Returns a time as a string value appropriate to the host environment's current locale. */  toLocaleTimeString(): string;  /** Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC. */  valueOf(): number;  /** Gets the time value in milliseconds. */  getTime(): number;  /** Gets the year, using local time. */  getFullYear(): number;  /** Gets the year using Universal Coordinated Time (UTC). */  getUTCFullYear(): number;  /** Gets the month, using local time. */  getMonth(): number;  /** Gets the month of a Date object using Universal Coordinated Time (UTC). */  getUTCMonth(): number;  /** Gets the day-of-the-month, using local time. */  getDate(): number;  /** Gets the day-of-the-month, using Universal Coordinated Time (UTC). */  getUTCDate(): number;  /** Gets the day of the week, using local time. */  getDay(): number;  /** Gets the day of the week using Universal Coordinated Time (UTC). */  getUTCDay(): number;  /** Gets the hours in a date, using local time. */  getHours(): number;  /** Gets the hours value in a Date object using Universal Coordinated Time (UTC). */  getUTCHours(): number;  /** Gets the minutes of a Date object, using local time. */  getMinutes(): number;  /** Gets the minutes of a Date object using Universal Coordinated Time (UTC). */  getUTCMinutes(): number;  /** Gets the seconds of a Date object, using local time. */  getSeconds(): number;  /** Gets the seconds of a Date object using Universal Coordinated Time (UTC). */  getUTCSeconds(): number;  /** Gets the milliseconds of a Date, using local time. */  getMilliseconds(): number;  /** Gets the milliseconds of a Date object using Universal Coordinated Time (UTC). */  getUTCMilliseconds(): number;  /** Gets the difference in minutes between the time on the local computer and Universal Coordinated Time (UTC). */  getTimezoneOffset(): number;  /**   * Sets the date and time value in the Date object.   * @param time A numeric value representing the number of elapsed milliseconds since midnight, January 1, 1970 GMT.   */  setTime(time: number): number;  /**   * Sets the milliseconds value in the Date object using local time.   * @param ms A numeric value equal to the millisecond value.   */  setMilliseconds(ms: number): number;  /**   * Sets the milliseconds value in the Date object using Universal Coordinated Time (UTC).   * @param ms A numeric value equal to the millisecond value.   */  setUTCMilliseconds(ms: number): number;   /**   * Sets the seconds value in the Date object using local time.   * @param sec A numeric value equal to the seconds value.   * @param ms A numeric value equal to the milliseconds value.   */  setSeconds(sec: number, ms?: number): number;  /**   * Sets the seconds value in the Date object using Universal Coordinated Time (UTC).   * @param sec A numeric value equal to the seconds value.   * @param ms A numeric value equal to the milliseconds value.   */  setUTCSeconds(sec: number, ms?: number): number;  /**   * Sets the minutes value in the Date object using local time.   * @param min A numeric value equal to the minutes value.   * @param sec A numeric value equal to the seconds value.   * @param ms A numeric value equal to the milliseconds value.   */  setMinutes(min: number, sec?: number, ms?: number): number;  /**   * Sets the minutes value in the Date object using Universal Coordinated Time (UTC).   * @param min A numeric value equal to the minutes value.   * @param sec A numeric value equal to the seconds value.   * @param ms A numeric value equal to the milliseconds value.   */  setUTCMinutes(min: number, sec?: number, ms?: number): number;  /**   * Sets the hour value in the Date object using local time.   * @param hours A numeric value equal to the hours value.   * @param min A numeric value equal to the minutes value.   * @param sec A numeric value equal to the seconds value.   * @param ms A numeric value equal to the milliseconds value.   */  setHours(hours: number, min?: number, sec?: number, ms?: number): number;  /**   * Sets the hours value in the Date object using Universal Coordinated Time (UTC).   * @param hours A numeric value equal to the hours value.   * @param min A numeric value equal to the minutes value.   * @param sec A numeric value equal to the seconds value.   * @param ms A numeric value equal to the milliseconds value.   */  setUTCHours(hours: number, min?: number, sec?: number, ms?: number): number;  /**   * Sets the numeric day-of-the-month value of the Date object using local time.   * @param date A numeric value equal to the day of the month.   */  setDate(date: number): number;  /**   * Sets the numeric day of the month in the Date object using Universal Coordinated Time (UTC).   * @param date A numeric value equal to the day of the month.   */  setUTCDate(date: number): number;  /**   * Sets the month value in the Date object using local time.   * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively.   * @param date A numeric value representing the day of the month. If this value is not supplied, the value from a call to the getDate method is used.   */  setMonth(month: number, date?: number): number;  /**   * Sets the month value in the Date object using Universal Coordinated Time (UTC).   * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively.   * @param date A numeric value representing the day of the month. If it is not supplied, the value from a call to the getUTCDate method is used.   */  setUTCMonth(month: number, date?: number): number;  /**   * Sets the year of the Date object using local time.   * @param year A numeric value for the year.   * @param month A zero-based numeric value for the month (0 for January, 11 for December). Must be specified if numDate is specified.   * @param date A numeric value equal for the day of the month.   */  setFullYear(year: number, month?: number, date?: number): number;  /**   * Sets the year value in the Date object using Universal Coordinated Time (UTC).   * @param year A numeric value equal to the year.   * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. Must be supplied if numDate is supplied.   * @param date A numeric value equal to the day of the month.   */  setUTCFullYear(year: number, month?: number, date?: number): number;  /** Returns a date converted to a string using Universal Coordinated Time (UTC). */  toUTCString(): string;  /** Returns a date as a string value in ISO format. */  toISOString(): string;  /** Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization. */  toJSON(key?: any): string;} interface DateConstructor {  new(): Date;  new(value: number): Date;  new(value: string): Date;  new(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date;  (): string;  readonly prototype: Date;  /**   * Parses a string containing a date, and returns the number of milliseconds between that date and midnight, January 1, 1970.   * @param s A date string   */  parse(s: string): number;  /**   * Returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date.   * @param year The full year designation is required for cross-century date accuracy. If year is between 0 and 99 is used, then year is assumed to be 1900 + year.   * @param month The month as an number between 0 and 11 (January to December).   * @param date The date as an number between 1 and 31.   * @param hours Must be supplied if minutes is supplied. An number from 0 to 23 (midnight to 11pm) that specifies the hour.   * @param minutes Must be supplied if seconds is supplied. An number from 0 to 59 that specifies the minutes.   * @param seconds Must be supplied if milliseconds is supplied. An number from 0 to 59 that specifies the seconds.   * @param ms An number from 0 to 999 that specifies the milliseconds.   */  UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number;  now(): number;}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
色老头一区二区三区| 欧美精品在线第一页| 欧美日韩一区二区三区在线免费观看| 成人午夜一级二级三级| 92裸体在线视频网站| 久久久久久久999精品视频| 精品久久久久久久久久久久久| 欧美肥臀大乳一区二区免费视频| 欧美激情亚洲一区| 国产精品狠色婷| 久久久久久香蕉网| 亚洲国产精品va在线看黑人动漫| 国产精品欧美日韩一区二区| 欧美精品一二区| 中文字幕综合在线| 久久久中文字幕| 97不卡在线视频| 久久久噜噜噜久噜久久| 久久综合久久88| 蜜臀久久99精品久久久久久宅男| 午夜精品久久久久久久久久久久| 性欧美xxxx视频在线观看| 91欧美视频网站| 亚洲高清色综合| 国产成人精品在线观看| 夜夜嗨av色综合久久久综合网| 亚洲国产精品资源| 亚洲欧洲日本专区| 日韩日本欧美亚洲| 国产91色在线免费| 国产成人avxxxxx在线看| 国产日本欧美一区二区三区| 久久久免费观看| 亚洲精品久久久久久久久久久久久| 欧美激情一区二区三区在线视频观看| 日韩欧美亚洲国产一区| 欧美日韩福利视频| 日韩欧美综合在线视频| 日韩av电影在线播放| 欧美第一黄色网| 欧美成人激情视频| 精品露脸国产偷人在视频| 亚洲精品国产欧美| 国产精品福利在线| 久久久久成人网| 北条麻妃久久精品| 欧美日韩在线视频一区二区| 成人av在线亚洲| 日韩电影网在线| 日本不卡视频在线播放| 成人欧美一区二区三区在线| 久久国产精品99国产精| 综合av色偷偷网| 在线视频欧美日韩精品| 国产精欧美一区二区三区| 欧美大秀在线观看| 亚洲人成在线观看| 亚洲国产成人久久| 这里只有精品在线播放| 欧美日韩精品国产| 欧美最近摘花xxxx摘花| 亚洲精品成人免费| 性色av一区二区三区| 亚洲国产高清高潮精品美女| 久久亚洲精品一区| 国产精品久久久久久亚洲影视| 亚洲最大的网站| 欧美激情亚洲精品| 久久精品国产96久久久香蕉| 欧美性猛交99久久久久99按摩| 亚洲视频在线观看免费| 欧洲美女7788成人免费视频| 久久高清视频免费| 91亚洲精品久久久久久久久久久久| 国产成人精品在线视频| 欧美一级片免费在线| 久久久国产精品亚洲一区| 欧美激情精品久久久久久黑人| 国产99久久精品一区二区| 日韩免费在线电影| 亚洲天堂av图片| 欧美激情国产高清| 国产精品高清在线| 国产精品第一视频| 欧美在线免费看| 韩日欧美一区二区| 国产精品久久久久免费a∨大胸| 最近2019年中文视频免费在线观看| 国产精品一区二区性色av| 国产亚洲精品美女| 亚洲精品网站在线播放gif| 亚洲美腿欧美激情另类| 亚洲欧美国产制服动漫| 久久久久久美女| 亚洲aaaaaa| 国产精品678| 97色在线观看| 欧美色欧美亚洲高清在线视频| 亚洲图片欧美午夜| 欧美日韩国产页| 欧美中文在线免费| 亚洲sss综合天堂久久| 日韩欧美综合在线视频| 亚洲一区中文字幕| 久久男人的天堂| 亚洲综合一区二区不卡| 亚洲国产成人精品女人久久久| 午夜剧场成人观在线视频免费观看| 国产精品美女免费视频| 色综合男人天堂| 亚洲午夜未满十八勿入免费观看全集| 久久久久久久影视| 亚洲精选一区二区| 九九视频直播综合网| 97在线免费观看视频| 欧美性极品xxxx娇小| 欧美激情在线观看| 日韩精品视频免费在线观看| 一区二区成人精品| 日韩中文字幕网| 成人精品久久一区二区三区| 精品久久久久久久久久久| 国产精品久久久久久超碰| 亚洲成人久久一区| 国产一区二区精品丝袜| 久久天天躁狠狠躁老女人| 久久精品成人欧美大片古装| 精品人伦一区二区三区蜜桃网站| 亚洲色图校园春色| 欧美主播福利视频| 国内偷自视频区视频综合| 欧美高清在线视频观看不卡| 26uuu亚洲国产精品| 亚洲欧美成人一区二区在线电影| 日韩精品久久久久久福利| 6080yy精品一区二区三区| 少妇av一区二区三区| 国产成人亚洲综合青青| 精品久久久久久久久久ntr影视| 欧美尺度大的性做爰视频| 亚洲精品视频二区| 超碰91人人草人人干| 成人午夜在线观看| 热re91久久精品国99热蜜臀| 日韩中文字幕在线精品| 亚洲天堂av高清| 国内精品视频久久| 8090理伦午夜在线电影| 亚洲国产精品高清久久久| 国产欧美日韩视频| 国产精品免费小视频| 国产精品揄拍500视频| 亚洲成人aaa| xxxx性欧美| 91国语精品自产拍在线观看性色| 97人人爽人人喊人人模波多| 91精品免费看| 亚洲国内精品在线| 国产拍精品一二三| 国产精品第8页| 欧美黑人视频一区| 深夜福利一区二区| 秋霞成人午夜鲁丝一区二区三区| 91精品啪aⅴ在线观看国产|