Android convert int timestamp to human datetime -


hi have android app using webrequestreturn timestamp of type int (or long) want convert human reader date time (according devices timezone)

for example 1175714200 convert gmt: wed, 04 apr 2007 19:16:40 gmt time zone: 4/5/2007, 3:16:40 gmt+8:00

i have use function convert seem not return correct result (all result (15/01/1970 04:04:25) not correct

time.settext(new simpledateformat("dd/mm/yyyy hh:mm:ss").                 format(new date(topstory.gettime() * 1000))); 

anything wrong above code?

i have warning message:

to local formatting use getdateinstance(), getdatetimeinstance(), or gettimeinstance(), or use new simpledateformat(string template, locale locale) example locale.us ascii dates. less... (ctrl+f1) callers should use getdateinstance(), getdatetimeinstance(), or gettimeinstance() ready-made instance of simpledateformat suitable user's locale. main reason you'd create instance class directly because need format/parse specific machine-readable format, in case want explicitly ask ensure ascii digits (rather than, say, arabic digits).

try function:

private string formatdate(long milliseconds) /* topstory.gettime()*1000 */ {     dateformat sdf = new simpledateformat("dd/mm/yyyy' 'hh:mm:ss");     sdf.settimezone(timezone.gettimezone("utc"));     calendar calendar = calendar.getinstance();     calendar.settimeinmillis(milliseconds);     timezone tz = timezone.getdefault();     sdf.settimezone(tz);     return sdf.format(calendar.gettime()); } 

it gets default timezone device it's being used on. if have questions/doubts, please comment. also, function takes input number of milliseconds since last epoch. if that's not topstory.gettime() returning, function not work. in case, need convert return value of topstory.gettime() number of milliseconds since last epoch.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -