If you have a comment on this topic, contact Aptify Documentation. If you want to return to the Aptify Community Site, please click here.

Work With Formatted Dates and Times

When you are coding in JavaScript and want to make sure you are using culture-formatted dates and times, the Aptify JavaScript API provides several ways to interact with them.

 

  1. If you want to format a date or datetime based on culture, you can use Aptify.framework.utility.getFormattedDateTime()

    Get Formatted Current Date/Time
    // Returns the current date and time as a string formatted for the user's Culture.
    Aptify.framework.utility.getFormattedDateTime(new Date());
    Get Formatted Date/Time
    // Takes a valid JSON-formatted date or datetime and returns it as a string formatted for the user's Culture.
    Aptify.framework.utility.getFormattedDateTime("2014-09-09T12:07:12.878Z");
  2. If you want to turn an already-formatted date (or datetime) into a JavaScript Date object without time information, you can use Aptify.framework.utility.getCultureDate().

    Parse a Formatted Date/Time String
    // Returns a JavaScript Date object, with the time information stripped out
    Aptify.framework.utility.getCultureDate("09/09/2014 05:37:12 PM")
     
    // Returns a JavaScript Date object
    Aptify.framework.utility.getCultureDate("12/09/2014")
     
    // So for both these calls, the time portion of the output is 00:00:00
    Parse an Invalid Formatted Date/Time String
    // Invalid date/time when the DateFormat is "MM/dd/yyyy"; returns null
    Aptify.framework.utility.getCultureDate("13/09/2014 05:37:12 PM")
  3. If you want to turn an already-formatted datetime into a JavaScript Date object with time information, you can use Aptify.framework.utility.getCultureDateTime().

    Parse a Formatted Date/Time String
    // Returns a JavaScript Date object
    Aptify.framework.utility.getCultureDateTime("09/09/2014 05:37:12 PM")
    Parse an Invalid Formatted Date/Time String
    // Invalid datetime, since it does not include time information; returns null
    Aptify.framework.utility.getCultureDateTime("13/09/2014 05:37:12 PM")
  4. If you want to turn a JavaScript Date object into a JSON-formatted datetime string, you can use Aptify.framework.utility.getJSONDateTime().

    Get JSON-Formatted String From JavaScript Date Object
    // Returns a JSON-formatted string representation of the current date and time
    Aptify.framework.utility.getJSONDateTime(new Date());
    

    You can go through getCultureDateTime() to use getJSONDateTime() on a culture-formatted datetime:

    Get JSON-Formatted String From Culture-Formatted String
    // Returns a JSON-formatted string representation of the culture-formatted datetime
    Aptify.framework.utility.getJSONDateTime(Aptify.framework.utility.getCultureDateTime("12/09/2014 05:37:12 PM"));

 

Copyright © 2014-2017 Aptify - Confidential and Proprietary