Adobe Dreamweaver Forums



Last 10 THreads :         GetFlashVars (Last Post : kaur.jsln@gmail.com - Replies : 0 - Views : 1 )           »          Creating PDF (Last Post : PJR - Replies : 1 - Views : 2 )           »          IE browser (Last Post : Karlhevera - Replies : 2 - Views : 4 )           »          Tag Heuer Link Womens Watch WT131C.BA0558 Recommendation DiscountWatches (Last Post : hjfakn@21cn.com - Replies : 0 - Views : 1 )           »          Creating Timetable using Datagrid (Last Post : anirudhs - Replies : 1 - Views : 3 )           »          Movado Faceto Mens Watch 0605042 Recommendation Discount Watches (Last Post : hjfakn@21cn.com - Replies : 0 - Views : 1 )           »          Contributor's Copies (Last Post : ThinkInk - Replies : 1 - Views : 3 )           »          You cannot perform this action in this region of thepage (Last Post : ThinkInk - Replies : 1 - Views : 2 )           »          Div tag on each other (Last Post : elakin - Replies : 11 - Views : 12 )           »          I'm in tears and ready to quit (Last Post : Deaf Web Designer - Replies : 75 - Views : 76 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flash
 
Tags:

Reply
  #1 (permalink)  
Old 07-23-2008, 07:56 PM
welling1977
 
Posts: n/a
Diggs:
Default Need to display another timezone at 12hr not 24hr.

I have a clock that displays the month, day, time (i.e. Jul. 23, 21:34p) but is
set to another time zone. However, with my current code the time is on a 24hr
clock and i need it to be on a 12hr one. Plus I need the time change to also be
reflected in the day and month rather than just the time. any idea how to do
this????

var dayText:String;
var dateText:String;
var monthText:String;
var AmPm:String;
_root.onEnterFrame = function() {
var myDateate = new Date();
var min:Number = myDate.getMinutes();
//the +12 is the current time plus 12 hours to be the new timezone
var hour:Number = myDate.getHours()+12;
var day:Number = myDate.getDay();
var date:Number = myDate.getDate();
var month:Number = myDate.getMonth();
min = min<10 ? "0"+min : min;

//AM/PM
if (hour>12) {
hour = hour-12;
AmPm = "p";
} else {
AmPm = "a";
}

//day
{
dateText = date+"";
}

//month
if (month == 0) {
monthText = "Jan";
} else if (month == 1) {
monthText = "Feb";
} else if (month == 2) {
monthText = "Mar";
} else if (month == 3) {
monthText = "Apr";
} else if (month == 4) {
monthText = "May";
} else if (month == 5) {
monthText = "Jun";
} else if (month == 6) {
monthText = "Jul";
} else if (month == 7) {
monthText = "Aug";
} else if (month == 8) {
monthText = "Sep";
} else if (month == 9) {
monthText = "Oct";
} else if (month == 10) {
monthText = "Nov";
} else if (month == 11) {
monthText = "Dec";
}

//display
//dateDisplay.text = hour+":"+min+ AmPm + "-" + monthText+"."+ dateText; };

dateDisplay.text = monthText+". "+ dateText+ ", "+ hour+":"+min+ AmPm; };

Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-24-2008, 12:55 PM
Noelbaland
 
Posts: n/a
Diggs:
Default Re: Need to display another timezone at 12hr not 24hr.

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_dateate = 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;
}

Reply With Quote
  #3 (permalink)  
Old 07-24-2008, 02:29 PM
welling1977
 
Posts: n/a
Diggs:
Default Re: Need to display another timezone at 12hr not 24hr.

Thanks so much for posting this. However, I'm trying to get it to work and
nothing is happening. I think I'm doing something wrong with creating my
dynamic text box and possibly naming it incorrectly--

I named the instance name date_txt (I also tried naming the var instance to
date_txt)

I'll keep playing with it. Thanks again!!!



Reply With Quote
  #4 (permalink)  
Old 07-24-2008, 03:08 PM
welling1977
 
Posts: n/a
Diggs:
Default Re: Need to display another timezone at 12hr not 24hr.

Duh! i just figured it out! add +12

var hour:Number = my_date.getHours()+12;

thanks!!
Reply With Quote
  #5 (permalink)  
Old 07-24-2008, 04:21 PM
welling1977
 
Posts: n/a
Diggs:
Default Re: Need to display another timezone at 12hr not 24hr.

Sorry to say, this isn't working. Adding +12 does not effect the date, only the
hour. So, for instance, It's Jul.24 12:01 p (where I am) and I want the clock
to read (Jul. 25 12:01 a) +12 hours for the time change. Instead, the clock
will read Jul.24 12:01a-- the date isn't effected.



Reply With Quote
  #6 (permalink)  
Old 07-24-2008, 04:21 PM
welling1977
 
Posts: n/a
Diggs:
Default Re: Need to display another timezone at 12hr not 24hr.

What is strange is that when I use it in my current fla., I only get "Thursday
24th"
and nothing more.

Everything appears as it should with your code in another file. Any ideas? I
do have some actionscript working at another place, but i took it off and it
still reads like this.



Reply With Quote
  #7 (permalink)  
Old 07-24-2008, 04:21 PM
welling1977
 
Posts: n/a
Diggs:
Default Re: Need to display another timezone at 12hr not 24hr.

Forget the above message-- my text box was too short-- (i must have the dumb today!)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 07:39 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk