Typography

活版印字


  • Home
  • Archive
  • Categories
  • Tags
  •  

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo

初探 momentjs

Posted at 2016-09-19 momentjs 

範例下載

時區之間的轉換

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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');
});

});

各國顯示格式之間的轉換

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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'));
});

});

Share 

 Previous post: Date 轉換 moment 格式 Next post: 初探 cucumberjs 

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo