Convert UTC Time T0 Local Time In Java or Groovy

后端 未结 2 1720
野趣味
野趣味 2021-01-05 17:49

i need to store createdOn (One Of the Attribute in Domain Class) . i am getting the system time and storing the value for this attribute.. My Time zone is (GMT+5:30 Chennai,

2条回答
  •  清酒与你
    2021-01-05 18:06

            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            sf.setTimeZone(TimeZone.getTimeZone("GMT"));
            System.out.println(sf.format(new Date()));
    
    
            SimpleDateFormat sf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            sf1.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
            System.out.println(sf1.format(new Date()));
            System.out.println(Arrays.asList(TimeZone.getDefault()));
    

提交回复
热议问题