Home > Programming > Get Unix timestamp in Java, Python, Erlang

Get Unix timestamp in Java, Python, Erlang

Mostly a note for myself. To Get Unix timestamp value in seconds

java:

long timestamp = System.currentTimeMillis()/1000

Python:

import time
timestamp = int(time.time())

Erlang:

{Mega, Secs, _} = now(),
Timestamp = Mega*1000000 + Secs,

Working with timestamps in MySQL

mysql> SELECT UNIX_TIMESTAMP('1997-10-04 22:23:00');
-> 875996580
mysql> SELECT FROM_UNIXTIME(1111885200);
+---------------------------+
| FROM_UNIXTIME(1111885200) |
+---------------------------+
| 2005-03-27 03:00:00 |
+---------------------------+

Categories: Programming Tags: , , , ,
  1. jeyc
    June 22, 2009 at 13:05 | #1

    thank you =) your post is usefull for me.

  2. May 10, 2010 at 10:41 | #2

    tnx a lot)

  3. June 2, 2010 at 22:20 | #3

    Thanks for the Java time stamp!

  4. Nik
    June 16, 2010 at 21:57 | #4

    The java method and the mysql method are inaccurate with each other. I’m using mysql server 5.0 and they often give results that are 1 hour apart (something to do with daylight savings time). WEEEAAAK

  5. Amr Khaled
    August 7, 2010 at 16:09 | #6

    Thanks for the Timestamp in MySQL info!

  6. surfrider
    October 28, 2011 at 08:52 | #7

    thanks for python!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.