Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get date representation in seconds?

I am using an API which requires a date parameter as a number of seconds, an int.

My problem is that I currently store this time in java.util.date and I was wondering if there is some way to convert the java.util.date variable to seconds so that I can fit it into the int parameter which the API requires?

like image 795
Sam Avatar asked Jun 19 '12 17:06

Sam


People also ask

How do you find date time and seconds?

Use the total_seconds() method of a timedelta object to get the number of seconds since the epoch. Use the timestamp() method. If your Python version is greater than 3.3 then another way is to use the timestamp() method of a datetime class to convert datetime to seconds.

How do you convert date to seconds?

To convert a date to seconds:Convert the result to seconds by dividing by 1000 .

How do you represent milliseconds?

A millisecond (from milli- and second; symbol: ms) is a unit of time in the International System of Units (SI) equal to one thousandth (0.001 or 10−3 or 1/1000) of a second and to 1000 microseconds.

How do you find the timestamp in seconds?

var currentDateTime = new Date(); To get the current date/time in seconds, use getTime()/1000.


1 Answers

import java.util.Date;

... long secs = (new Date().getTime())/1000; ...

Please see - http://docs.oracle.com/javase/6/docs/api/java/util/Date.html#getTime()

like image 138
Karthik Kumar Viswanathan Avatar answered Sep 29 '22 22:09

Karthik Kumar Viswanathan