Hi there,
All that was needed to get the 24 to a 12 hour clock was to subtract 12 from
the getHours() property.
Below is a script I created that shows just about every date method you can
use. It's set to a 12 hour clock rotation and includes adding a suffix for the
date and the leading 0 for minutes and seconds. Also it uses arrays and loops
instead of if/else statements.Have a look at it and adjust it to your script.
Hope it helps
// Array to hold our month names
var months:Array = new Array("January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December");
// Array to hold our day of the week names
var days:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday");
// Function to loop thru the months array and pull
// out and return the right month name
function get_month(num:Number)
{
for(var i=0; i<months.length; i++){
if(i == num){
var mon = months[i];
return mon;
}
}
}
// Function to loop thru the days array and pull
// out and return the right day of the week name
function get_days(num:Number)
{
for(var i=0; i<days.length; i++){
if(i == num){
var day = days[i];
return day;
}
}
}
// Attaches the leading 0 to seconds and minutes
// for numbers from 0 - 9
function get_zeroes(num:Number)
{
if(num < 10){
var min = num.toString();
min = "0" + min;
} else {
min = num;
}
return min;
}
// Returns the date and the correct suffix for that date
function get_date(num:Number)
{
// Default
var suffix:String = "th";
if(num == 1 || num == 21 || num == 31){
suffix = "st";
}
if(num == 2 || num == 22){
suffix = "nd";
}
if(num == 3 || num == 23){
suffix = "rd";
}
// Concatenates the date and suffix
var return_date = num + suffix;
return return_date;
}
_root.onEnterFrame = function()
{
var my_date

ate = new Date();
var hour:Number = my_date.getHours();
var min:Number = my_date.getMinutes();
var day:Number = my_date.getDay();
var date:Number = my_date.getDate();
var month:Number = my_date.getMonth();
var year:Number = my_date.getFullYear();
var seconds:Number = my_date.getSeconds();
var ampm:String;
var hour_12:Number;
var date_txt:String;
// This is the main check for the 12 - 24 hour difference
// It subtracts 12 from the getHours() property and returns
// the number in a new variable(hour_12). It also determines
// the AM/PM suffix
if(hour > 12){
hour_12 = hour-12;
ampm = "pm";
} else {
hour_12 = hour;
ampm = "am";
}
date_txt = get_days(day)+" "+get_date(date)+" "+get_month(month)+", "+year+"
"+hour_12+":"+get_zeroes(min)+":"+get_zeroes(secon ds)+" "+ampm.toUpperCase();
// Textfield on stage that displays date/time
tf.text = date_txt;
}