Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combined date and time representation in Bash

Tags:

How can I obtain current date in the following format using Bash

YYYY-MM-DDThh:mm:ss

like image 378
Misha Slyusarev Avatar asked Oct 24 '13 08:10

Misha Slyusarev


People also ask

How do I display 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 # ...

What is date +% s in bash?

date +%S. Displays seconds [00-59] date +%N. Displays in Nanoseconds. date +%T.

What is $@ in bash?

bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.

What does [- Z $1 mean in bash?

$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.


1 Answers

With these options:

$ date "+%Y-%m-%d %H:%M:%S" 2013-10-24 10:40:12 

or even (thanks Birei!)

$ date "+%F %T" 2013-10-24 10:40:12 

All format controls can be get from man date.

I don't know what your T means, but for example you have:

$ date "+%F %T %Z" 2013-10-24 10:40:12 CEST 
like image 174
fedorqui 'SO stop harming' Avatar answered Feb 21 '23 02:02

fedorqui 'SO stop harming'