Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Date/Time Format Showinf different in Win/Linux OS's.

Explorer ,
Sep 19, 2014 Sep 19, 2014

Hello All,

I know in the DateTimeFormatter page in Adobe's AS3 API reference guide (*see below for link) that is says it could display differently depending on the Operating System, if you are using Locale ID, or something along those lines (*but I'm not using that in my code)...

          http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/formatters/DateTimeFormatte...

When viewing my DateTime variable in Linux, the Time part (*for Hours) is getting a zero added to beginning of it, if the hour is currently in the single digits, i.e. 1 through 9 am/pm. But, if I view the swf in Internet Explorer or Firefox or Chrome in Windows, the Time is not getting the Zero added to it. I was thinking I could probably just add some code to remove the zero if HOUR begins with ZERO -->  "^0" Regex.

But, I wanted to see if maybe there was something in my code that could be changed to fix this instead..?

Here is my DateTime code:

//Declare a Date variable to hold the Date and Time in the Wallboard's Clock:

var date:Date = new Date();

//FORMATTING THE DATE:

        var date_formatter:DateTimeFormatter = new DateTimeFormatter("en-US");

            /*****************************************************************

             * EEEE = Day of Week            MMM = Abbrv Month Name   *

             * yyyy = Shows the Full year     dd = Day of the Month          *

             *****************************************************************/

             date_formatter.setDateTimePattern("MMM dd");                    //--> "Sep 19"

             var myDate:String = date_formatter.format(date);

        //FORMATTING THE DAY OF THE WEEK:

        var day_formatter:DateTimeFormatter = new DateTimeFormatter("en-US");

             day_formatter.setDateTimePattern("EEEE");                    //--> "Monday"

             var myDay:String = day_formatter.format(date);

        //FORMATTING THE TIME OF DAY:

        var time_formatter:DateTimeFormatter = new DateTimeFormatter("en-US");

            /*****************************************************************

             *  h = Current Hour    mm = Current Minute        a = AM|PM  *

             *****************************************************************/

             time_formatter.setDateTimePattern("h:mm a");

             var myTime:String = time_formatter.format(date);

       //Combine Date/Times into strings and insert into TextFIeld:

        var date_line1:String = "<font color='#FFFFFF' size=22>" + myDay + ", " + myDate + "</font>";

        var time_line2:String = "<font size=65 color='#FFFFFF'>" + myTime + "</font>";


So I then assign those strings to a TextField and display the textfield.


*Here's an example of what the TextField looks like:

         Windows Shows:

                    _________________

                   |      Friday, Sept 19      |

                   |_____2:33 PM___|

              Linux Shows:

                    _________________

                   |      Friday, Sept 19      |

                   |____02:33 PM___|

Does anyone see anything in my code that I could chnage that would fix this issue? I was thinking if there was a way to check which OS is running I could then use the correct format string depending on the OS, but I didn't see any documentation for which format strings work for which Operating System...

Any thoughts or suggestions would be greatly appreciated...

Thanks in Advance,

Matt

TOPICS
ActionScript
220
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 22, 2014 Sep 22, 2014
LATEST

Well, I still didn't find anything online about the Formatting, but I did add this code below as a workaround and it seems to be doing the trick...

################################# CODE ################################

     //Create REGEX(s) to search the Time Variable for:

     var leadingZero_REGEX:RegExp = /^0/gi

     var nonLeadingZero_REGEX:RegExp = /^[1-9]/gi

     //Check if 'myTime' begins with a "ZERO" (*for the hours section):

     if (myTime.search(leadingZero_REGEX) != -1)

     {

          //Slice the 1st character from the myTime variable:

          var tmp_myTime:String = myTime.slice(1);

          //If tmp_myTIme, which is what the slice result was set to, begins with a 1 to 9, then set myTime to tmp_myTime...

          if (tmp_myTime.search(nonLeadingZero_REGEX) != -1) {

               myTime = tmp_myTime;

          }

     }

############################### END CODE ###############################



So with the code above, the time "01:45 PM" becomes --> "1:45 PM"...



Thanks,

Matt

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines