Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert timestamps to dates in Bash?

I need a shell command or script that converts a Unix timestamp to a date. The input can come either from the first parameter or from stdin, allowing for the following usage patterns:

ts2date 1267619929 

and

echo 1267619929 | ts2date 

Both commands should output "Wed Mar 3 13:38:49 2010".

like image 521
chiborg Avatar asked Mar 03 '10 12:03

chiborg


People also ask

How do I convert timestamps to dates?

You can simply use the fromtimestamp function from the DateTime module to get a date from a UNIX timestamp. This function takes the timestamp as input and returns the corresponding DateTime object to timestamp.

How do I manually convert a timestamp to a date?

To easily convert UNIX timestamp to date in the . csv file, do the following: 1. =R2/86400000+DATE(1970,1,1), press Enter key.

How do I change the date format in bash?

Bash Date format YYYY-MM-DD To format date in YYYY-MM-DD format, use the command date +%F or printf "%(%F)T\n" $EPOCHSECONDS . The %F option is an alias for %Y-%m-%d . This format is the ISO 8601 format.

How do I echo date and time in bash?

Sample shell script to display the current date and time #!/bin/bash now="$(date)" printf "Current date and time %s\n" "$now" now="$(date +'%d/%m/%Y')" printf "Current date in dd/mm/yyyy format %s\n" "$now" echo "Starting backup at $now, please wait..." # command to backup scripts goes here # ...


1 Answers

On systems with GNU Coreutils >= 5.3.0, e.g. Linux you can use:

date -d @1267619929 
like image 92
a'r Avatar answered Oct 08 '22 05:10

a'r