Setting time zone of a java.util.Date

0 votes

Can someone help me in specifying the time zone of a date object that I have parsed from a String?
The timezone is not specified in the String but by default, it is setting the local time zone as the time zone of the date object.
 Please suggest.

Aug 14, 2018 in Java by 93.lynn
• 1,620 points

1 answer to this question.

0 votes

You can make use of the following DateFormat.

SimpleDateFormat myDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date newDate = myDate.parse("2010-05-23T09:01:02");

You need to do this because by default java.util.Date objects do not contain any timezone information.

answered Aug 14, 2018 by anto.trigg4
• 3,440 points

Related Questions In Java

0 votes
2 answers

Converting between java.time.LocalDateTime and java.util.Date

Try this: Date in = new Date(); LocalDateTime ldt ...READ MORE

answered Aug 27, 2019 in Java by Sirajul
• 58,130 points
0 votes
0 answers

How to manage two JRadioButtons in java so that only one of them can be selected at a time?

How to manage two JRadioButtons in java ...READ MORE

Apr 21 in Java by kartik
• 31,010 points
0 votes
2 answers

How do I get the current date and time using Java?

If you require a time stamp in ...READ MORE

answered Aug 23, 2019 in Java by Sirajul
• 58,130 points
0 votes
1 answer

How do I create a Java string from the contents of a file?

If you're looking for an alternative that ...READ MORE

answered Apr 19, 2018 in Java by Rishabh
• 3,580 points
0 votes
1 answer

The best way to filter a Java Collection?

 this problem is solved using streams and ...READ MORE

answered May 28, 2018 in Java by Parth
• 4,640 points
0 votes
2 answers

How can I get the filenames of all files in a folder which may or may not contain duplicates

List<String> results = new ArrayList<String>(); File[] files = ...READ MORE

answered Sep 12, 2018 in Java by Sushmita
• 6,890 points
0 votes
1 answer
0 votes
2 answers

Scanner is skipping nextLine() after using next() or nextFoo()?

use input.nextLine(); after your nextInt() function for example:- input.nextInt(); ...READ MORE

answered May 11, 2019 in Java by Sourav Dangi
+1 vote
2 answers

Retrieve all the implementations of an interface in Java

Take a look to this example: ...READ MORE

answered Dec 20, 2019 in Java by Roberto
• 370 points

edited Jul 6 by Roberto 9,805 views
0 votes
1 answer

Gracefully stopping a java thread

The preferable way will be to use a ...READ MORE

answered Aug 20, 2018 in Java by anto.trigg4
• 3,440 points