LoginSignup
0
0

More than 1 year has passed since last update.

ISO 8601(日付時刻表記法)の基本形式から拡張形式へ変換

Last updated at Posted at 2022-01-08

こんにちは。
ISO 8601(日付時刻表記法)の基本形式から拡張形式へ変換しました。ただし処理ロジックが甘いです。

  • 基本形式: 20211225T000000.000+0900
  • 拡張形式: 2021-12-25T00:00:00.000+09:00
const getDateTimeExtended = str => {
    const len = str.length;
    const Y =   str.slice(0, 4) + '-';
    const M =   str.slice(4, 6) + '-';
    const Dh =  str.slice(6, 11) + ':';
    const m =   str.slice(11, 13) + ':';
    const st =  str.slice(13, len-2)  + ':';
    const u =   str.slice(len-2, len);
    const str_extended = Y + M + Dh + m + st + u;
    return str_extended;
}
0
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
0
0