1. #1
    Sencha User
    Join Date
    Nov 2010
    Posts
    36
    Vote Rating
    1
    kaendsle is on a distinguished road

      0  

    Default Unanswered: Ext.Date.format() only prints locale strings?

    Unanswered: Ext.Date.format() only prints locale strings?


    I have Date objects that were set using a UTC time and I want to recover that time when formatting them using Ext.Date.format(). A very simple example demonstrates that Ext.Date.format() will print a locale string.

    Code:
    var d = new Date('1998-04-15T20:00:00.0000Z');
    
    d.toUTCString();
    // "Wed, 15 Apr 1998 20:00:00 GMT"
    
    Ext.Date.format(d, 'H:i')
    // "16:00"
    
    Ext.Date.format(Ext.Date.parse('1998-04-15T20:00:00.0000Z', 'c'), 'H:i')
    // "16:00"
    I need my time string formatted a certain way, and Ext.Date.format() is extremely helpful in that regard. However, I need it to format the date as a UTC string, not a locale string. Relative to the above example, I need a way to output the string "20:00" instead of the string "16:00".

    Is this not supported? I will just have to concatenate the outputs from d.getUTCHours() and so forth?

  2. #2
    Sencha - Support Team
    Join Date
    Feb 2013
    Location
    California
    Posts
    5,447
    Vote Rating
    113
    Answers
    202
    Gary Schlosberg is just really nice Gary Schlosberg is just really nice Gary Schlosberg is just really nice Gary Schlosberg is just really nice Gary Schlosberg is just really nice

      0  

    Default


    I guess so. Looks like the Date docs page describes something similar in the ISO 8601 formatted dates section:
    http://docs.sencha.com/extjs/4.2.1/#!/api/Date
    Are you a Sencha products veteran who has wondered what it might be like to work at Sencha? If so, please reach out to our human resources manager: fabienne.bell@sencha.com

  3. #3
    Sencha User
    Join Date
    Nov 2010
    Posts
    36
    Vote Rating
    1
    kaendsle is on a distinguished road

      1  

    Default


    This is the best solution I've been able to come up with to mitigate this fact:

    Code:
    Ext.Date.format(Ext.Date.add(date, Ext.Date.MINUTE, date.getTimezoneOffset()), formatString)
    ...Where date is a Date object in UTC and formatString is the desired PHP-esque format string to output. The above expression subtracts the timezone offset, producing a Date object with the wrong time, but effectively writing the correct time as a String despite the locale time formatting.

Thread Participants: 1

Tags for this Thread