Tag Info

New answers tagged

2

With bash-4.2 or above: printf '%(%F %T)T\n' 1234567890 (where %F %T is the strftime()-type format) That syntax is inspired from ksh93. In ksh93 however, the argument is taken as a date expression where various and hardly documented formats are supported. For a Unix epoch time, the syntax in ksh93 is: printf '%(%F %T)T\n' '#1234567890' ksh93 however ...


2

With zsh you could use the strftime builtin: strftime format epochtime Output the date denoted by epochtime in the format specified. e.g. zmodload zsh/datetime strftime '%A, %d %b %Y' 1234567890 Saturday, 14 Feb 2009


0

Since you asked for the year, ls -lac is an easy one to remember if, like me, you use ls -la all the time. The c gives you ctime which will display a year if it's not the current year or the hour and minute if it is.


9

Using GNU date : $ date -d '2015-09-26 +30 days' '+%Y-%m-%d' 2015-10-26


2

According to the source of parse-datetime.y of gnulib, it seems to be a feature related to the function time_zone_hhmm. First, we cannot use your format to add seconds : date +"%Y-%m-%d %H:%M:%S" --date="2015-07-27 00:11:22 - 00:05:01", I'm having a parse error : date: invalid date ‘2015-07-27 00:11:22 - 00:05:01’ Then, according to the header of the ...


0

I tried python on the command line. root@messagerie-secours[10.10.10.19] ~/SCRIPTS/MAIL # python -c "import datetime; print datetime.date.today() - datetime.date(2014,11,17)" 246 days, 0:00:00 root@messagerie-secours[10.10.10.19] ~/SCRIPTS/MAIL #


0

From: comment at site and also another answer , some examples how to achieve this with exiftool: exiftool “-DateTimeOriginal+=0:1:2 3:4:5″ exiftool -DateTimeOriginal+='5:10:2 10:48:0' exiftool -DateTimeOriginal-='0:0:0 1:3:0'


11

echo $(( (`date +%s` - `date +%s -d '2014/11/17'`) / 86400 )) days ago


5

Well, on the face of it: $ date --date="-239 days" Mon Nov 17 15:25:40 CET 2014 In a script (not very efficient, but... maybe it handles leap seconds? ;) ) i=0 result="" while [ "$result" != "20141117" ] do i=$((i+1)) result=$(date --date="-$i days" +%Y%m%d) done echo "$i" days have passed since "$result"


7

With zsh you could use the strftime builtin (available via zsh/datetime) with -r (reverse): strftime -r format timestring which uses format to parse the timestring and output the number of seconds since epoch: zmodload zsh/datetime strftime -r %Y-%b-%d 2015-Jul-13 1436734800 This errors out if the date is invalid: strftime -r %Y-%b-%d 2015-Jul-33 ...


11

From manpage:- DATE STRING The --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday". A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty ...


11

GNU date does not support YYYY-MMM-DD. However, it does understand DD-MMM-YYYY. So if you really have to handle dates of this format you can do it with something like this, which simply swaps the arguments around to a format that date expects: ymd='2015-Jul-13' dmy=$(echo "$ymd" | awk -F- '{ OFS=FS; print $3,$2,$1 }') if date --date "$dmy" >/dev/null ...


2

Look at the ls -l /etc/localtime to see at what time the change happened. Then look through logs such as /var/log/audit/audit.log and /var/log/secure for what might have started at around that time. Note that now systemd has taken over /etc/localtime and there is a command timedatectl set-timezone <zone> that can change this file too. Also, there ...


1

If your AIX has at least Perl 5.9, then you can use the Time::Piece core module to obtain the timezone offset in seconds: perl -MTime::Piece -le '$t=Time::Piece->new;print $t->tzoffset' For a particular timezone, do: TZ=Australia/Darwin perl -MTime::Piece -le '$t=Time::Piece->new;print $t->tzoffset'


1

If your goal is to calculate the difference in hours between UTC/GMT and local time, just ask it this way: UTC=$(date -u +%H) LT=$(date +%H) DIFF=$((UTC - LT)) taking care to note that the result may be negative depending on time of day and relative locations.


2

There is no such thing as "local time in epoch format", date +%s always prints the number of seconds since the epoch, namely since 1970-01-01 UTC. It's the same number in all timezones. However, with most strftime(3) implementations date +%z will print the numeric offset of the specified timezone: $ TZ=Australia/Darwin date +%z +0930 $ TZ=America/Toronto ...


3

You can compare file timestamps directly in bash/zsh/ksh with the test operator -nt (newer-than). You can also use touch to set a time on a file, eg 0:00 for midnight today. So simply: touch -d '0:00' /tmp/midnight if [ file -nt /tmp/midnight ] ...



Top 50 recent answers are included