Languages
[Edit]
EN

Bash - current timestamp

9 points
Created by:
martineau
1170

In this short article, we would like to show how to print the current timestamp under Linux using Bash.

Quick solution (run following commands):

date +%s
date "+%Y%m%d%H%M%S"

Example output:

1613387500
20210215120029

Where the timestamp contains: full year, month, day, hours, minutes and seconds.

 

Note: read this article to see milliseconds time examples.

Other cases

Command	                        Example output             Note

date +%s	                    1613387500                 # seconds since 1970-01-01 00:00:00 UTC
date +%s%3N	                    1613387500137              # %3N is not supported always
date +%s%N	                    1613387500137650679        # %N is not supported always
date "+%Y%m%d%H%M%S"	        20210215120029
date "+%Y%m%d%H%M%S%3N"	        20210215120029137
date "+%Y%m%d_%H%M%S"	        20210215_120029
date "+%Y%m%d_%H%M%S%3N"	    20210215_120029137
date "+%Y_%m_%d_%H_%M_%S"	    2021_02_15_12_00_29
date "+%Y_%m_%d_%H_%M_%S_%3N"	2021_02_15_12_00_29_137
date "+%Y.%m.%d %H:%M:%S"	    2021.02.15 12:00:29
date "+%Y.%m.%d %H:%M:%S.%3N"	2021.02.15 12:00:29.137
date "+%Y-%m-%d %H:%M:%S"	    2021-02-15 12:00:29
date "+%Y-%m-%d %H:%M:%S.%3N"	2021-02-15 12:00:29.137
date "+%Y.%m.%dT%H:%M:%S%z"	    2021.02.15T12:00:29+0100

Alternative titles

  1. Linux - current timestamp
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Bash

Bash - current timestamp
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join