Skip to content Skip to sidebar Skip to footer

Get Current Time On The Device When Server Has Gmt

I have the following code below in the server stored as gmt and would like it to change based on android device timezone.I am getting wrong value unable to figure out the mistake.I

Solution 1:

public String TimeFormating(String Time)
 {
     SimpleDateFormat format_before = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
     SimpleDateFormat format_to_Convert = new SimpleDateFormat("hh:mm a",Locale.getDefault());

     format_before.setTimeZone(TimeZone.getTimeZone("GMT"));
     format_to_Convert.setTimeZone(TimeZone.getDefault());
     Date time = null;
     try 
     {    
         time = format_before.parse(Time);

     } catch (ParseException e) 
     {
         e.printStackTrace();
     }

     return format_to_Convert.format(time).toLowerCase(Locale.getDefault());

 }

Post a Comment for "Get Current Time On The Device When Server Has Gmt"