Question

Ok another question, How would i go about setting the current date/time when the user hits a submit button, into a file name for an output string.

i know how to set a standard static file name ie. files/receipt.txt and also researched how to format standard output of the time and date using <s:DateTimeFormatter id="dateTimeFormatter" dateStyle="short" timeStyle="short" locale="en-AU" /> that changes Tue Jun 11 15:48:14 GMT+1000 2013 into this 11/06/2013 3:50 PM

  1. now i need to know how to remove the spaces for a file name and
  2. how to set a variable file name ( like "files/todaysDate.txt" )

And thank you in advance !!!

Was it helpful?

Solution

You can get the date straight from the DateFormatter. For example, getting current Date & time to String:

//..
var todaysDate:String = getCurrentDate();
//..

private function getCurrentDate():String{
        var CurrentDateTime:Date = new Date();
        var CurrentDF:DateFormatter = new DateFormatter();
        CurrentDF.formatString = "MM/DD/YY LL:NN:SS A"
        var DateTimeString:String = CurrentDF.format(CurrentDateTime);
        return DateTimeString;

    }

So in your case you could use this as formatString:

 CurrentDF.formatString = "MM_DD_YY_LL_NN_SS_A"

so your string would look like 12_06_2013_12_56_AM.

OTHER TIPS

Set the formatString property on the DateFormatter. Here's the documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top