티스토리 뷰

공부

[MacOSX] ISO 8601 format

승가비 2022. 7. 20. 12:54
728x90

https://unix.stackexchange.com/questions/374389/formatting-the-date-in-bash/710512#710512
https://www.vankuik.nl/2019-04-23_ISO_date_on_macOS

 

Formatting the date in bash

I would like to format the date in bash in a script. The format is: 2016-10-05T12:18:36.890+02:00 I'm currently using: $(date +%Y%m%d%H%M%S) Any idea how this can be done?

unix.stackexchange.com

 

vankuik.nl: 2019-04-23 ISO date on macOS

To print the current date in ISO 8601 format on macOS: $ date +%Y-%m-%dT%H:%M:%S 2019-04-23T14:44:46 To print it with the timezone information, append %z. $ date +%Y-%m-%dT%H:%M:%S%z 2019-04-23T14:44:42+0200 Note that in the last case, you're missing the c

www.vankuik.nl

zone=$(date +%z)
datetime=$(date +%Y-%m-%dT%H:%M:%S)

iso=$datetime${zone:0:3}:${zone:3:2}

echo $iso
728x90

'공부' 카테고리의 다른 글

[CI] ktlint & detekt  (0) 2022.07.22
[github] auto-author-assign  (0) 2022.07.22
[Presto] DATE_ADD, DATE_DIFF  (0) 2022.07.20
[Spring] @ConditionalOnProperty  (0) 2022.07.20
Multi-armed Bandit  (0) 2022.07.20
댓글