Created
September 30, 2022 06:48
-
-
Save krdlab/26cb21ceee2dc566d0d41a2dd9d3e2ac to your computer and use it in GitHub Desktop.
date-fns で日時文字列をパース & フォーマット
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { parse, format } = require('date-fns'); | |
const { utcToZonedTime } = require('date-fns-tz'); | |
function formatDateString(s) { | |
const date = parse(s, 'EEE, dd MMM yyyy HH:mm:ss xx', new Date()); | |
return format(utcToZonedTime(date, 'Asia/Tokyo'), 'yyyy/MM/dd'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment