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()

    // Returns the current date and time as a string formatted for the user's Culture.
    Aptify.framework.utility.getFormattedDateTime(new Date());
    // 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().

    // 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
    // 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().

    // Returns a JavaScript Date object
    Aptify.framework.utility.getCultureDateTime("09/09/2014 05:37:12 PM")
    // 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().

    // 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:

    // 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"));

 

Related articles

Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.