I have a date format yyyy/mm/dd hh:mm:ss in GMT format. I want to convert the date from GMT format to BST time. What's the simplest way to do this?
            Asked
            
        
        
            Active
            
        
            Viewed 5,124 times
        
    1
            
            
         
    
    
        eebbesen
        
- 5,070
- 8
- 48
- 70
 
    
    
        Rory Lester
        
- 2,858
- 11
- 49
- 66
- 
                    possible duplicate of [Convert Date/Time for given Timezone - java](http://stackoverflow.com/questions/7670355/convert-date-time-for-given-timezone-java) – ug_ Mar 09 '15 at 10:30
- 
                    2Just one comment. There is no GMT format. The format of the date and the timezone are two different shoes. I guess you want to know what local BST time your GMT time is, right? – ReneS Mar 09 '15 at 10:34
1 Answers
3
            
            
        With Java 8, the easiest way is probably to:
- parse the date into a LocalDateTime
- use it to create a ZonedDateTime using GMT time zone
- change the time zone to BST
- get the LocalDateTime of that new date
Sample example:
String date = "2015/03/09 10:32:00";
LocalDateTime gmt = LocalDateTime.parse(date, DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"));
ZonedDateTime instant = ZonedDateTime.of(gmt, ZoneId.of("GMT"));
LocalDateTime bst = instant.withZoneSameInstant(ZoneId.of("Europe/London")).toLocalDateTime();
System.out.println(bst);
If you change the month to July, for example, you should see an offset of one hour as expected.
(I assumed that BST is British Summer Time - it could also be Bangladesh Standard Time: in general it is better to use the full name of the time zone to avoid ambiguities).
 
    
    
        assylias
        
- 321,522
- 82
- 660
- 783