2

I am convert date/time in string to datetime apex using datetime.parse().But it is is subtracting 1 min..

 String s1='5/23/2013';
 String t1='10:00 PM';
 String s2=s1+' '+t1;
 Datetime d=Datetime.parse(s2);

 Event ev= new Event();
 ev.Subject=meet.subject__c;
 ev.ownerid=userinfo.getuserid();
 ev.StartDateTime=datetime.now().adddays(1);
 ev.EndDateTime=d;

When i am saving this record to salesforce it is subtracting 1 min less.. i dont know why..? my saved record is showing 9:59 PM

1 Answer 1

1

To help sort your problem out, I'd suggest you add some system assert or debug statements to your code.

String s2=s1+' '+t1;
SystemAssert(s2, '5/23/2013 10:00 PM');

or

String s2=s1+' '+t1;
SystemDebug(s2);

which won't stop the execution, but will give you the value of s2 before parsing

I'd also recommend moving the

Datetime d=Datetime.parse(s2); 

into your Event creation statement as:

ev.EndDateTime=Datetime.parse(s2);

and again, I'd add a SystemDebug(s2) here to see what the value is

2
  • thanks mate for replying...i tried but its not working...its still saving 1 min earlier...i dont know why..??
    – miku
    Commented May 22, 2013 at 16:46
  • Did the system debugs show it as being the correct value in both places?
    – crmprogdev
    Commented May 22, 2013 at 17:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .