Convert Date/Time for given Timezone - java

前端 未结 16 2493
孤城傲影
孤城傲影 2020-11-22 12:36

I want to convert this GMT time stamp to GMT+13:

2011-10-06 03:35:05

I have tried about 100 different combinations of DateFormat, TimeZone,

16条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 12:54

    A quick way is :

    String dateText ="Thu, 02 Jul 2015 21:51:46";
    long hours = -5; // time difference between places
    
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(E, dd MMM yyyy HH:mm:ss, Locale.ENGLISH);     
    LocalDateTime date = LocalDateTime.parse(dateText, formatter);        
    date = date.with(date.plusHours(hours));
    
    System.out.println("NEW DATE: "+date);
    

    Output

    NEW DATE: 2015-07-02T16:51:46

提交回复
热议问题