初探 momentjs
Posted at 2016-09-19 momentjs
範例下載
時區之間的轉換
1234567891011121314151617181920
describe('timezone', function() { var patterm = 'YYYY-MM-DD HH:mm:ss'; var newYork; before(function() { newYork = moment.tz('2014-06-01 00:00:00', 'America/New_York'); }); it('us convert to tw', function() { var tw = newYork.clone().tz('Asia/Taipei'); tw.format(patterm).should.equal('2014-06-01 12:00:00'); }); it('us convert to jp', function() { var jp = newYork.clone().tz('Asia/Tokyo'); jp.format(patterm).should.equal('2014-06-01 13:00:00'); });});
各國顯示格式之間的轉換
1234567891011121314
describe('locale', function() { it('us', function() { moment.locale().should.equal('en'); moment().format('L').should.equal(moment().format('MM/DD/YYYY')); }); it('ja', function() { moment.locale('ja'); moment.locale().should.equal('ja'); moment().format('L').should.equal(moment().format('YYYY/MM/DD')); });});
Previous post: Date 轉換 moment 格式 Next post: 初探 cucumberjs