• narasimharaju monapati 6
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Can anybody help me How to change the datetime field from any other timezone(Which is coming from a picklist) to GMT. My exact requirement is change the datetime field  to a timezone which is coming from the picklist and again converting into GMT. 

My code is below here

DateTime CurentTime = system.now();
String TimeZones = '(GMT+05:30) India Standard Time (Asia/Kolkata)';
List<String> lststrsplit = TimeZones.substring(12,TimeZones.length()).split('\\(',2);
        string strTimeZone = lststrsplit[1].substring(0,lststrsplit[1].length()-1);
        system.debug(CurentTime+'abc#');
        string strCurrentTime = CurentTime.format('YYYY-MM-dd HH:mm:ss', strTimeZone);
        Datetime dateCurrentTime = Datetime.valueof(strCurrentTime);
        
        string strGMTTimeZone = 'GMT';
        string strGMTtime = dateCurrentTime.format('MM-dd-YYYY HH:mm:ss', strGMTTimeZone);
        Datetime DateGMtTime = Datetime.valueofGMT(strCurrentTime);
system.debug( strCurrentTime);

Couldn't find any doc /api reference that explicitly describes how to convert a given GMT Datetime to a desired TimeZone Datetime.  All of the docs talk about GMT and "Local" TimeZone, unless I've missed something obvious.

 

I have start and end dates in the database, which are in GMT TimeZone.  I need to convert them to a different TimeZone (BusinessHours TimeZone) so that I can use "BusinessHours.diff" API to determine elapsed time.

 

Thanks

 

 

 

 

 

 

 

 

Message Edited by jps on 10-29-2009 09:22 PM
  • October 30, 2009
  • Like
  • 0