• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

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
0
Siddhardh
Asked:
Siddhardh
  • 4
  • 3
1 Solution
 
CEHJCommented:
Just set the TimeZone on the DateFormat you use to format/parse it
0
 
SiddhardhAuthor Commented:
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);
0
 
CEHJCommented:
Yes:
formatter.setTimeZone(TimeZone.getTimeZone("GMT-12"));

Open in new window

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
SiddhardhAuthor Commented:
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
0
 
SiddhardhAuthor Commented:
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);
0
 
SiddhardhAuthor Commented:
Hopefully it will work :P
0
 
CEHJCommented:
>>/// do i need Locale.US ????

No. Not unless you need it for some reason
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now