Activity Forums Salesforce® Discussions Conversion of String to DateTime format in Salesforce Org

  • sushant

    Member
    January 10, 2017 at 1:57 pm

    Hi Kumar,

    Looks like DateTime.parse() takes the string and parses it based on the context users locale to produce a GMT date/time in the database. DateTime.format(String) should create an output string in based on the timezone of the current context user.

    So you should be able to use when data comes in:

    DateTime dt = DateTime.parse('11/6/2014 12:00 AM');
    Then when you go to call the web service you'd use something like:

    String dtOut = dt.format('d/M/y'); -- Or M/d/y if you're using American dates.
    And for the bonus, you could just use a different argument in the format function such as:

    String timOut = dt.format('h:m a');

    Hope this helps you

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos