本文介紹了Moment.js 從日期獲取日期名稱的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我將 jquery 和 moment.js 用于自定義日歷.
I'm using jquery and moment.js for a custom calendar.
我在變量 myDate
中有一個(gè)日期對(duì)象,例如:
I have a date object in a variable myDate
like :
Object { date="2014-12-23 14:00:00", timezone_type=3, timezone="Europe/Paris"}
我想,使用 moment.js(或不使用)獲取此日期的日期名稱,在我的示例中,我需要獲取:tuesday
I want, using moment.js (or not) get the day name of this date, in my example i need to get : tuesday
想法?謝謝
推薦答案
現(xiàn)在你可以解析你擁有的日期字符串:
With moment you can parse the date string you have:
var dt = moment(myDate.date, "YYYY-MM-DD HH:mm:ss")
這是針對(duì) UTC 的,如果您愿意,您必須從該點(diǎn)轉(zhuǎn)換時(shí)區(qū).
That's for UTC, you'll have to convert the time zone from that point if you so desire.
然后你可以得到星期幾:
Then you can get the day of the week:
dt.format('dddd');
這篇關(guān)于Moment.js 從日期獲取日期名稱的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!