Link to home
Start Free TrialLog in
Avatar of Siddhardh
Siddhardh

asked on

Convert Long datatype into a DateTime of a Particular TimeZone

Hello I would like to convert Long datatype into datatime of TimeZone that user selects example :

TimeZone selected : GMT-1200
long Num = 1226505300156

how can i get it in DateTime ?

Appreciate help
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Just set the TimeZone on the DateFormat you use to format/parse it
Avatar of Siddhardh
Siddhardh

ASKER

Can you solve this please

TimeZone selected : GMT-1200
long Num = 1226505300156

long time = scan.getTimeinLong();

DateFormat formatter = new SimpleDateFormat("MM-DD-YYYY:hh:mm:ss", Locale.US); /// do i need Locale.US ????
TimeZone tz = TimeZone.getTimeZone(q.getTimezone()); // ex:GMT-1200
formatter.setTimeZone(tz);
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok what you did is one step less from waht i did thank you though

i need the long to be converted into that TimeZone
long time = scanTask.getPickupConfig();
                                     
                                    DateFormat formatter = new SimpleDateFormat("MM-DD-YYYY:hh:mm:ss", Locale.US);
                                  formatter.setTimeZone(TimeZone.getTimeZone(gdsQueue.getTimezone()));
                                                                formatter.format(time);
Hopefully it will work :P
>>/// do i need Locale.US ????

No. Not unless you need it for some reason