RSS

Code to convert Date Time to GMT format

18 Jun

What is GMT?
– GMT stands for “Greenwich Mean Time”.
– It’s nothing but the reference point for us to understand the date time of specific country.
– It is used as the basis for standard time in most countries of the world.
– When we try to calculate difference between two countries time then we calculate by using GMT format.
Or simply we perform transaction with GMT.
E.g. To calculate IST with GMT, we just add +5.30 with IST time to get the GMT.

Note: Default time format of SQL is GMT. It’s standard way to perform DML (Insert, Update, and Delete) operations in GMT format.

To pass value to convertDateTimeToGMT()
– First parse your string in date format.
– This will return you long
E.g.
long objDate = Date.parse(strDate)

private static void convertDateTimeToGMT(long objDate)
{
String strGMTFormat = null;
SimpleDateFormat objFormat;
Calendar objCalendar;
try
{
//Specify your format
objFormat = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
//Convert into GMT format
objCalendar = Calendar.getInstance(new SimpleTimeZone(0, “GMT”));
objFormat.setCalendar(objCalendar);
strGMTFormat = objFormat.format(objDate);
}
catch (Exception e)
{
e.toString();
}
finally
{
objFormat = null;
objCalendar = null;
}
}

Advertisements
 
Leave a comment

Posted by on June 18, 2012 in Android Source Code

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: