Skip to main content

Datetime dt = DateTime.parse('10/14/2011 11:46 AM');

String myDtString = dt.format();

system.assertEquals(myDtString, '10/14/2011 11:46 AM');

System.TypeException: Invalid date/time: 10/14/2011 11:46 AM

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_datetime.htm

Any thoughts why i am getting this error and how I could rectify it?

Please suggest me that how can i convert above string to salesforce date time.

 
1 Antwort
  1. 1. Nov. 2017, 13:02
    parse(datetimeString)

    Constructs a Datetime from the given String in the local time zone and in the format of the user locale.

    That is formatted for the English (United States) locale. 

    The Salesforce locale settings determine the display formats for date and time, users’ names, addresses, and commas and periods in numbers.

    Supported Locales​ : Date and time format according the locale settings

    https://help.salesforce.com/articleView?id=admin_supported_locales.htm&type=0

    <your name> > My Settings > Language & Time Zone > Locale

    French (France, Euro) = fr_FR_EURO = Euro: EUR = 28/02/2008 16:30 = dd/MM/yyyy HH:mm

    English (United States) = en_US = U.S. Dollar: USD = 2/28/2008 4:30 PM = MM/dd/yyyy hh:mm a
0/9000