Conversion of local time zone to GMT in java

前端 未结 3 1724
青春惊慌失措
青春惊慌失措 2020-12-30 13:05

Am trying convert date which is in local time zone to GMT, i did some thing like this

SimpleDateFormat sdf = new SimpleDateFormat(\"MM/dd/yyyy HH:mm:ss\");         


        
3条回答
  •  清歌不尽
    2020-12-30 13:40

    import java.util.*;
    import java.text.*;
    public class CurrentTimeToGMT{
      public static void main(String args[]){
        Date date = new Date();
        DateFormat gmtFormat = new SimpleDateFormat();
        TimeZone gmtTime = TimeZone.getTimeZone("GMT");
        gmtFormat.setTimeZone(gmtTime);
        System.out.println("Current Time: "+date);
        System.out.println("GMT Time: " + gmtFormat.format(date));
    
      }
    }
    

    Output

    Current Time: Wed Mar 10 11:21:18 IST 2010
    
    GMT Time: 3/10/10 5:51 AM
    

提交回复
热议问题