[SalesForce] Changing date format

I am inserting one record to Custom_object__c that object contains the DateTime field,here am a russian user to insert.If i use a date format as "Startdate:22.02.2014"(JSON request) means its accept, if i use date format as "Startdate:22/02/2014"(JSON request) its not accept it shows Invalid date:22/02/2014 date error. My salesforce admin is a UK user.How to resolve this using Datetime methods i try it through datetime methods but it throwing a error as Invalid date..

Input format as

"ArraySample":[
    {
      "ID" : "107081070810708",
      "samplevalue" : "apple",
      "StartDate" : "20/2/2014",
      "StartTime" :"10:02:00"

    }
]
  • This format is working for United Kingdom(UK "StartDate" :"20/2/2014") Russian Country date format is dd.mm.yyyy but am
    giving StartDate as 20/2/2014 its throwing a error as Invalid
    date:20/2/2014.

How can resolve this issue using apex class?

Best Answer

I am assuming the JSON is received or sent between different systems. So why not use the ISO date format http://www.w3.org/TR/NOTE-datetime ?

And then in apex

DateTime dt = (datetime)json.deserialize('"2014-06-20T20:55:00.000Z"', datetime.class);
Related Topic