0

I need to convert the string getting from JSON (For eg: 2014-08-26T17:50:20.000-0700) to this format '6/9/2014 11:57' to store in field which is of text format in salesforce.

Also per my requirement the field which i store date should not be in date/time format.

2 Answers 2

1

What about to use something like this that also handle the timezone (in case daylight saving changes too )

Datetime GMTDate = Datetime.newInstance(myDate.year(),myDate.year().month(), myDate.year().day(),0,0,0);
String strConvertedDate = GMTDate.format('MM/dd/yyyy HH:mm','America/Mexico_City');
1
  • Note you should use M/d instead of MM/dd because the OP requested 6/9, not 06/09.
    – Adrian Larson
    Jan 4, 2017 at 14:10
1

You can use

Date dt = Date.valueOf('2014-08-26T17:50:20.000-0700');

String dts = DateTime.newInstance(dt.year(), dt.month(), dt.day()).format('d-MM-YYYY');

System.debug(logginglevel.error, dts);

You must log in to answer this question.

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