moment.js(js date)日期格式化處理插件強大,
官方網站:http://momentjs.com/你也能夠查看官方網站E文原版moment.js api。
當前日期格式化
moment().format('MMMM Do YYYY, h:mm:ss a'); -> 四月 6日 2015, 3:55:57 下午 moment().format('dddd'); -> 星期一 moment().format("MMM Do YY"); -> 4月 6日 15 moment().format('YYYY [escaped] YYYY'); -> 2015 escaped 2015 moment().format(); -> 2015-04-06T15:55:57+08:00 --------------------------------------------------- moment().format('YYYY-MM-DD'); -> 2015-04-06 moment().format('YYYY-MM-DD h:mm:ss a'); -> 2015-04-06 03:55:57 下午 指定日期格式化 moment("20111031", "YYYYMMDD").fromNow(); -> 3年前 moment("20120620", "YYYYMMDD").fromNow(); -> 3年前 moment().startOf('day').fromNow(); -> 16小時前 moment().endOf('day').fromNow(); -> 8小時內 moment().startOf('hour').fromNow(); -> 1小時前 當前日期向前或者向後推的日期格式化 moment().subtract(10, 'days').calendar(); -> 2015年3月27日 moment().subtract(6, 'days').calendar(); -> 上週二下午3點55 moment().subtract(3, 'days').calendar(); -> 上週五下午3點55 moment().subtract(1, 'days').calendar(); -> 昨天下午3點55 moment().calendar(); -> 今天下午3點55 moment().add(1, 'days').calendar(); -> 明天下午3點55 moment().add(3, 'days').calendar(); -> 本週四下午3點55 moment().add(10, 'days').calendar(); -> 2015年4月16日 也可使用下面方式日期格式化 moment().format('L'); -> 2015-04-06 moment().format('l'); -> 2015-04-06 moment().format('LL'); -> 2015年4月6日 moment().format('ll'); -> 2015年4月6日 moment().format('LLL'); -> 2015年4月6日下午3點55 moment().format('lll'); -> 2015年4月6日下午3點55 moment().format('LLLL'); -> 2015年4月6日星期一下午3點55 moment().format('llll'); -> 2015年4月6日星期一下午3點55 實際應用中,好比能夠很方便的獲得上週的開始日期和結束日期等,可以靈活運用moment.js各類日期處理都不在話下,轉自:http://www.51xuediannao.com/js/texiao/moment.html