1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

moment.jsを使ってhh:mmの文字列から時間と分を取得する

Last updated at Posted at 2017-08-30

備忘です。

07:00という文字列から、7と0というnumberをmoment.jsを使って取り出す方法。

timeStringToNumber.js
var timeString = '07:00';
var numberHh = Number(moment(timeString, 'HH:mm').format('H'));
var numberMm = Number(moment(timeString, 'HH:mm').format('m'));
console.log(numberHh); // 7 should be shown on your log console.
console.log(numberMm); // 0 should be shown on your log console.
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?