Tuesday, 15 March 2011

android - Convert the time string received from server to local time -


Users post messages to my server which are stored in a database with a column, by default are CURRENT_TIMESTAMP . Like below:

  Message table: Sender | Content | Sentimam Tom | Hello there 2013-06-19 00:13:21   

When a user posts a message to my server, it does not need to post it to my local time. My database record is that automatically the value I think is that this message is better after sending a message to the user

Later the user will retrieve the message from the server as well as the time it was sent. I am wondering how to convert that time to the user's local time.

If I am using Jason to encode on the server then I can decode the data in my app. So the time received from the server will be a string: 2013-06-19 00:13:21 I think I need to start this string?

You must parse the returned server with the SimpeDateFormat:

  SimpleDateFormat simpleDateFormat = New SimpleDateFormat ("Yyyy-MM-dd HH: mm: SS"); SimpleDateFormat.setTimeZone (TimeZone.getTimeZone ("approximate")); Date Date = Simple Data Format PRS ("2013-06-19 00:13:21"); Timezone destTz = Timezone.Gate Time Zone ("Your Timezone"); SimpleDateFormat.setTimeZone (destTz); String result = Simple data format (date);    

No comments:

Post a Comment