How does the Unix time format work? For example, the Unix time for 3:00 PM is:

Normal time format <----3:00PM = 1402565420----> Unix Time

How can I make it understand the time as 3:00 PM ?

  • 3
    1402565420 may be 3pm on a specific date in your specific timezone. Tomorrow 3pm in your timezone will be 1402651820. See en.wikipedia.org/wiki/Unix_time for details: "Unix time (aka POSIX time or Epoch time), is a system for describing instants in time, defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970." – yeti Jun 12 '14 at 9:55
  • 1
    To convert these tomestamps, try date -d @1402565420 or TZ=your-timezone-abbreviation date -d @1402565420. – yeti Jun 12 '14 at 10:00
  • Wow Cool the command Works Perfect – Babin Lonston Jun 12 '14 at 10:34

The Unix time is given as seconds since the epoch: the number of seconds (not counting leap seconds) that have passed since 00:00:00 Coordinated Universal Time (UTC), or Thursday, January 1st, 1970,

The GNU date command has some very nice features that allow you to translate between different time formats. These are explained very nicely in man date so I will only give you some examples here:

### "Normal" format
$ date
Thu Jun 12 11:44:23 CEST 2014
### Unix time
$ date +%s

To convert, you can give date a specific date using the -d flag. However, to get a Unix date, this needs to be a full date. You can't convert 3:00PM to Unix time since Unix time refers to an entire date (year,month,day,time). So, for example, to get the Unix date for the 12th of September 1987, you would do:

$ date -d "3 PM 12 September 1987" +%s

And to convert that back to a "normal" date:

$ date -d "@558450000" 
Sat Sep 12 15:00:00 CEST 1987
  • date -d 3pm will still work and is the same as date -d "3pm today" – Stéphane Chazelas Jun 12 '14 at 10:04
  • @StéphaneChazelas yes, but as you said, it will give today's time. The point I was making to the OP is that 3:00PM is meaningless in terms of Unix time and only 3:00 PM today makes sense. – terdon Jun 12 '14 at 10:07
  • 2
    I suggest that it should be noticed that Unix time is absolute, while my "3pm today" can be very different from your "3pm today"... depending on $TZ. – Rmano Jun 12 '14 at 15:16
  • 1
    @Rmano, yes, and also note that things like 1am can be ambiguous as in most countries (the ones implementing DST) there is one day of the year where that time occurs twice. – Stéphane Chazelas Oct 13 '16 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.