Atefeh Rashidi
Atefeh Rashidi

Reputation: 515

How to get timeStamp in java like this code in C#

How can I re-write the code below (that is written in C#), in java to get same result?

TimeSpan Now = DateTime.UtcNow.Subtract(new DateTime(1970,1, 1));
long TimeStamp = Convert.ToInt64(Math.Floor(Now.TotalMilliseconds));

I want to translate the C# code to java language to get the value of TimeStamp (long variable).

Upvotes: 1

Views: 1512

Answers (2)

Michael Markidis
Michael Markidis

Reputation: 4191

Just use:

long timestamp = System.currentTimeMillis();

Upvotes: 1

Moolerian
Moolerian

Reputation: 562

you can use this :

 java.util.Date date= new java.util.Date();
  System.out.println(new Timestamp(date.getTime()));

Upvotes: 1

Related Questions