You need to sign in to do that
Don't have an account?
rajesh k 10
Urgent:How to convert String(Tue Nov 18 00:00:00 GMT 2014) to Date(11/18/2014)?
Hi,
I have Two Strings Like
String s1='Tue Nov 18 00:00:00 GMT 2014';
String s2='Sun Nov 30 00:00:00 GMT 2014';
How To get s1 and s2 are like below
o/p:s1=11/18/2014
s2=11/130/2014
help me...
I have Two Strings Like
String s1='Tue Nov 18 00:00:00 GMT 2014';
String s2='Sun Nov 30 00:00:00 GMT 2014';
How To get s1 and s2 are like below
o/p:s1=11/18/2014
s2=11/130/2014
help me...
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008wAgIAI
I tried this URL i didn't get output like Date s1=11/18/2014
please help me....
Datetime GMTDate = Datetime.newInstanceGmt(2011,6,1,12,1,5);
String strConvertedDate = GMTDate.format('MM/dd/yyyy HH:mm:ss', 'America/New_York');
System.assertEquals( '06/01/2011 08:01:05', strConvertedDate);
I tried but i got DateTime Not Exist Error ..
Please convert your date in below format. Then try below code:-
String s1='11/6/2014 12:00 AM';
DateTime dt = DateTime.parse(s1);
String utcDt = dt.format('dd-MM-yyyy', 'UTC');
System.debug('----------->'+utcDt );
Thanks,
Amit Chaudhary
In debug log my date is 2014-11-20 00:00:00
I an visualforce page visible like 'Tue Nov 20 00:00:00 GMT 2014';
NOTE:In visualforce page i was using Datepicker
I tries but i didn't get 2014-11-20 date
Below code will resolve your issue :-
String myDate = 'Tue Nov 18 00:00:00 GMT 2014';
String strMnth = myDate.substring(4,7);
String day = myDate.substring(8,10);
String year = myDate.substring(24,28);
string strMonth ;
if(strMnth=='Jan')
strMonth ='1';
else if (strMnth == 'Nov' )
strMonth ='11';
String strDate = strMonth +'/'+day+'/'+year;
System.debug('------>'+strDate );
Please add all else for all 12 mnths
Thanks
Amit Chaudhary
Thank you for reply
Below String how to assighn Date field?
String strDate = strMonth +'/'+day+'/'+year;
My code:
=======
String myDate = cookiestartdate; //Sat Nov 22 00:00:00 GMT 2014
String strMnth = myDate.substring(4,7);
String day = myDate.substring(8,10);
String year = myDate.substring(24,28);
string strMonth ;
if(strMnth=='Jan')
strMonth ='1';
else if (strMnth == 'Nov' )
strMonth ='11';
Startdate = String.valueOf(strMonth +'/'+day+'/'+year);//Here Startdate is the date picker field Datatype Date
System.debug('------>'+Startdate);
I tried below code
String myDate = cookiestartdate;
String strMnth = myDate.substring(4,7);
String day = myDate.substring(8,10);
String year = myDate.substring(24,28);
string strMonth ;
if(strMnth=='Jan')
strMonth ='1';
else if (strMnth == 'Nov' )
strMonth ='11';
String strDate = strMonth +'/'+day+'/'+year;
Startdate = date.parse(strDate);
System.debug('------>'+Startdate);
I get Starting position out of bounds: 24 Error
Please use below code :-
String myDate = 'Tue Nov 18 00:00:00 GMT 2014';
String strMnth = myDate.substring(4,7);
String day = myDate.substring(8,10);
String year = myDate.substring(24,28);
string strMonth ;
if(strMnth=='Jan')
strMonth ='1';
else if (strMnth == 'Nov' )
strMonth ='11';
String strDate = strMonth +'/'+day+'/'+year;
System.debug('------>'+strDate );
date mydate1 = date.parse(strDate);
System.debug('------>'+mydate1 );
PS: if this answers your question then hit Like and mark it as solution!
Well above code is working fine for me:-
I also get like your debug only .
When i refresh page on that time debuglog Startdate is--------------------------> 2014-11-22 00:00:00
In an visualforce field location is------------> Sat Nov 22 00:00:00 GMT 2014
Based on which i will assign startdate inputText value(Datepicker)?
Please send me your Apex and VF page code. So that i check.
Thanks
Amit Chaudhary
string orderdate= thisDT.format('MM/dd/yyyy','GMT'); //output of this was 01/01/2019
when you format the datetime , it convert with userlocal time. so you need to change converted format in GMT.