java - Today epoch time irrespective of current time -
i trying epoch time of today's date. stuck parseexception
on formatting date.
snippet:-
simpledateformat df = new simpledateformat("dd/mm/yyyy"); string str = df.format(calendar.getinstance().gettime()); date date = df.parse(str); long epoch = date.gettime(); log.i("epoch" , string,valueof(epoch));
how 1 can today's epoch time?
if you're interested in current time since jan 1 1970 utc in milliseconds, use system.currenttimeinmillis()
. no need format , parse strings in process.
to unix epoch timestamp it, convert seconds dividing 1000.
based on comments , own answer seem interested in epoch timestamp in timezone. use calendar
that, no need format , parse strings here either:
calendar c = calendar.getinstance(); // today c.settimezone(timezone.gettimezone("utc")); // comment out local system current timezone c.set(calendar.hour, 0); c.set(calendar.minute, 0); c.set(calendar.second, 0); c.set(calendar.millisecond, 0); long millistamp = c.gettimeinmillis(); long unixstamp = millistamp / 1000;
Comments
Post a Comment