日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jquery 毫秒转换成日期_基于jQuery的时间戳与日期间的转化

發布時間:2025/3/21 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jquery 毫秒转换成日期_基于jQuery的时间戳与日期间的转化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文實例為大家分享了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;

}

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

總結

以上是生活随笔為你收集整理的jquery 毫秒转换成日期_基于jQuery的时间戳与日期间的转化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 中文字幕第22页 | 99视频在线| 黄p在线播放 | 无遮挡国产 | 少妇无码av无码专区在线观看 | 国产一级二级三级视频 | 成人免费在线播放 | 欧美高清性 | 亚洲射射射 | 啪啪av导航 | 天天操夜夜爱 | 精品国模一区二区三区欧美 | 男女做爰猛烈高潮描写 | 少妇偷人精品无码人妻 | 91久久一区 | 中文字幕av在线免费 | 国产高清精品软件丝瓜软件 | 伊人天堂av | 4色av| 欧美网| 国产精品--色哟哟 | 国产91啪| 91免费.| 天天色影院 | 天天色成人网 | 国产麻豆精品在线 | 狠狠做深爱婷婷久久综合一区 | 欧美亚洲韩国 | 欧美日韩免费一区二区 | 波多野结衣国产在线 | 欧美综合图区 | 色欲av伊人久久大香线蕉影院 | 免费中文av | 一二三四av | 东北熟女一区二区三区 | 偷拍欧美亚洲 | 国产亚洲精品成人无码精品网站 | 特级丰满少妇一级aaaa爱毛片 | 久久人妻免费视频 | 91在线视频观看 | 一区二区三区国产精品视频 | 天堂中文资源在线观看 | 日本韩国毛片 | 在线播放波多野结衣 | eeuss国产一区二区三区 | 日韩av午夜 | 插插操操 | 国产欧美精品久久 | 日韩av一区在线 | 91精品国产综合久久福利 | 美女100%露胸无遮挡 | 秋霞福利| 色综合色婷婷 | 人成在线免费视频 | 久久精品亚洲无码 | 亚洲黄网在线观看 | 梦梦电影免费高清在线观看 | 日韩激情网站 | 天天骑夜夜操 | av官网在线观看 | 国产婷婷综合 | 日韩中文字幕网 | 欧美交换配乱吟粗大25p | 亚洲AV无码成人精品国产一区 | 爱如潮水3免费观看日本高清 | 天美麻花果冻视频大全英文版 | 国产精品久久一区二区三区动 | 91精产国品一二三 | 骚视频在线观看 | 美女被变态侵犯 | 中文字幕免费高清网站 | 九一爱爱 | 国产精品三级电影 | 国产一级片免费播放 | 国产精品女人精品久久久天天 | 国产白浆一区二区 | 法国空姐在线观看视频 | 日韩中文字幕av电影 | 日韩成人免费视频 | 久久国产综合 | 天堂在线视频免费观看 | 亚洲网站在线 | 中文资源在线播放 | 国产在线综合视频 | 国产调教打屁股xxxx网站 | 三年中文在线观看中文版 | 国产精品亚洲无码 | 日韩精品免费一区二区在线观看 | 国产三级久久久久 | 91麻豆国产在线观看 | 狠狠操操 | 91国产高清 | 扒下小娇妻的内裤打屁股 | 午夜影院a | 毛片无限看 | 熊出没之冬日乐翻天免费高清观看 | 黄色片网站免费在线观看 | 91午夜在线 | 成人免费看片网站 |