'How to generate date in this format (2022-04-29T06:07:28.158Z) in linux

Looking for solution to generate date in the below format:

2022-04-29T06:07:28.158Z

Have to use in bash script.



Solution 1:[1]

It looks like you want to have the milliseconds included (rounded to three places), so add %3N to pmf's suggestion from the comments:

date -u +%FT%T.%3NZ

Example output:

2022-04-29T16:23:39.905Z

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeff Schaller