How to get current date time in milliseconds in android -
this question has answer here:
- get current time , date on android 31 answers
i trying save file name current date , time in milliseconds. , while reading file want read latest one.here code
calendar rightnow = calendar.getinstance(); long offset = rightnow.get(calendar.zone_offset) + rightnow.get(calendar.dst_offset); string sincemidnight = long.tostring((rightnow.gettimeinmillis() + offset) % (24 * 60 * 60 * 1000)); return sincemidnight+"_"+filename;
i think can use this
long time= system.currenttimemillis();
this return current time in milliseconds mode . surely work
long time= system.currenttimemillis(); android.util.log.i("time class ", " time value in millisecinds "+time);
here logcat using above function
05-13 14:38:03.149: info/time class(301): time value in millisecinds 1368436083157
if got doubt millisecond value .check here
edit : time zone used demo code ist ,so if check milliseconds
mentioned in code to match time in log other time zone specify ist zone.
edit: easy approach .but if need time zone or other details think won't enough also see approach using android api support
Comments
Post a Comment