Today's Question:  What are bad parts of Windows 10?       GIVE A SHOUT

Technical Article => Operating System =>  Linux/Unix

Convert time to Unix time

 sonic0002     2013-01-19 09:04:17      2,819    0    0

Unix time is defined as the number of seconds that have elapsed since midnight Coordinated Universal Time (UTC), 1 January 1970,not counting leap seconds. It is used widely in Unix-like and many other operating systems and file formats. It is neither a linear representation of time nor a true representation of UTC. Unix time may be checked on some Unix systems by typing date +%s on the command line.

Sometimes it's a bit difficult to compare times stored in different applications or systems with different formats. For example, if we want to compare a DATE in Oracle with a date string in Unix, we need to convert them into a common time type so that they can be compares easily. The common way is we can convert them to UNIX timestamp and then compare which one is larger.

Now we will show how to convert time to UNIX timestamp.

In Oracle, if we have a DATE type, we can convert it into UNIX timestamp using following.

TO_NUMBER(date-TO_DATE(''01-Jan-1970 00:00:00', 'DD-Mon-YYYY HH24:MI:SS'))*24*60*60

In UNIX, if we have date string like "2013-01-19 23:02:01", then we can convert it into UNIX timestamp using

date --date="2013-01-19 23:02:01" +%s

If you want to get the last modified time of a file in UNIX timestamp format, you can use:

stat -c %Y filename

Hope this can help you when you want to compare time from different applications or systems.

 Tags : UNIX time, Oracle DATE, conversion, timestamp   Read(2,819) Comment(0) Version(0)

  SAVE AS PDF   MARK AS READ   MARK AS IMPORTANT

 RELATED


 COMMENT  (TOTAL 0 COMMENT)


No comment for this article.


Nickname  
Email 
Comment

Can you guess the end?

By sonic0002
When two cars are competing for the same lane, the unexpected happens.

 CONTRIBUTE


Share your geeky stuff now.
You make the world better, the world makes us better.

 WRITE ARTICLE

 VERSION


No other version available yet.