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?
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.
To convert a date to seconds:Convert the result to seconds by dividing by 1000 .
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.
var currentDateTime = new Date(); To get the current date/time in seconds, use getTime()/1000.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With