遊客:  註冊 | 登錄 | 幫助





標題: [求助] javascript date-time problem
mickeyGoUp     Rank: 7Rank: 7Rank: 7
版主
性別 男
UID 5

精華 0
帖子 35511
積分 5235   詳情

閱讀權限 150
註冊 2006-3-24
來自 美國滴滴尼
狀態 離線

 
 
 
 
發表於 2007-9-19 10:42 AM  資料  個人空間  短訊  加為好友 
Ohhh I think I finally understand what exactly you want to do!  So the index.html file only points to one set of file at a time, and you want it to show different set when the index.html is being view at different time of the day!

Yes, that can definitely be done in javascript.  I am kind of in a hurry so I will give you some codes but I don't have time to test them.  You can put those logics in the mainSwf.js file. If that does not work, either lhy or myself will correct it later.  

var d = new Date(); //this get the current date-time

var hours = d.getHours(); //get the hour portion of the current time

if (hours >= 0 && hours < 12) {
    document.write('<param name="movie" value="morning.swf">');
} if (hours >= 12 && hours < 18) {
    document.write('<param name="movie" value="afternoon.swf">');
} else {
    document.write('<param name="movie" value="night.swf">');
}


頂部

GT2     Rank: 3
青出藍
性別 男
UID 4090

精華 0
帖子 906
積分 244   詳情

閱讀權限 40
註冊 2006-8-5
來自
狀態 離線

 
 
 
 
發表於 2007-9-19 11:34 AM  資料  個人空間  短訊  加為好友 
Hi mickeyGoUp,

Thanks a lot.

Yes,that is what I want to do.I will try it and tell you ok or not.
May be my explanation is not so clear,so make both of you be confusion.Really sorry about that.

I have another question about the url,do I need to open a new topic or just ask you over here??

頂部

GT2     Rank: 3
青出藍
性別 男
UID 4090

精華 0
帖子 906
積分 244   詳情

閱讀權限 40
註冊 2006-8-5
來自
狀態 離線

 
 
 
 
發表於 2007-9-19 12:06 PM  資料  個人空間  短訊  加為好友 
Hi mickeyGoUp,

I tested the script already,that is ok.
I think that is a so basic script,but I cannot recall my learning.
I know that is too bad as I think just call out  someone for help and no need to think about it anymore.(self-examination)
Really sorry for bother you and lhy,I am so appreciate your concern.

頂部

lhy     Rank: 3
青出藍
性別 男
UID 14043

精華 0
帖子 121
積分 330   詳情

閱讀權限 40
註冊 2006-10-16
來自 Netherlands
狀態 離線

 
 
 
 
發表於 2007-9-19 05:09 PM  資料  個人空間  短訊  加為好友 
Mickey is too Quick!

GT2 next time you better say in which direction you need to go to achieve your goal instead of asking for solution.

If you hit on a problem you better break it down into small pieces. This way it will make things clear.

Let’s say that there’s something that you need to get done. Something challenging which will take up some time, like learning a new programming language, writing a game demo, starting a company, invading Poland, etc.

First, what is it that you’re wanting to do? Try and be as specific as you can. Write it down as if you were writing an email to ask someone else to do it. Break the high level goal down into some of the main stages.

In your case, you need to determine the current time first. After that you need to try to define which part of the day is the current time (morning, afternoon, evening). After that output what you wanted to show.

Break your problem down in small pieces and think about what you need to make it work. This way makes programming much easier.  (Just a tip).



最後編輯: lhy : 2007-9-19 05:10 PM
頂部

mickeyGoUp     Rank: 7Rank: 7Rank: 7
版主
性別 男
UID 5

精華 0
帖子 35511
積分 5235   詳情

閱讀權限 150
註冊 2006-3-24
來自 美國滴滴尼
狀態 離線

 
 
 
 
發表於 2007-9-19 07:25 PM  資料  個人空間  短訊  加為好友 
Good tips, lhy!!  

GT2, no need to feel bad!  It is OK to ask.  I am bad in memorizing things too.  I cannot even remember the codes that I wrote 3 months ago.  So I always just ask my co-workers instead of wasting time looking for answers.  Of course if they don't remember neither, then no choice, have to find it myself.    But lhy is right, you have to know HOW to ask, and in the process of asking, sometimes, by describing your own problems, a solution might pop-up in ur mind.  

The following are the refined version of the same codes.  It is better to cut down duplicated codes for easier maintenance.  

var d = new Date(); //this get the current date-time

var hours = d.getHours(); //get the hour portion of the current time

var filename = "";

if (hours >= 0 && hours < 12) {
    filename = "morning.swf";
} if (hours >= 12 && hours < 18) {
    filename = "afternoon.swf";
} else {
    filename = "night.swf";
}

document.write('<param name="movie" value="' + filename + '">');

For new topic, please start a new thread.    And can you change the subject of this current thread to "Javascript date-time problem"?  Thanks.

頂部

GT2     Rank: 3
青出藍
性別 男
UID 4090

精華 0
帖子 906
積分 244   詳情

閱讀權限 40
註冊 2006-8-5
來自
狀態 離線

 
 
 
 
發表於 2007-9-20 09:59 AM  資料  個人空間  短訊  加為好友 
Morning lhy & mickeyGoUp,

Yes,both of you are right.Thank you for your tip!!!
I must try to narrow the possibilities to find out the answer or solution.
At first,I think if I say all the process from beginning,that might be easy to understand.But it is wrong,will being contrary!!!Next time,I will sharp to the point(I hope I can).
Ok,I will change the thread to js. problem.
Once again,thanks a lot!!!

mickeyGoUp :
No problem, GT2! ^^ Looking forward to helping you with your next question. ^^

頂部


快速美言











一群熱心會員對本主題作出以下的回覆:

mickeyGoUp: RMK added - PID 133368 [ view ]



最後回覆日期: 2007-9-20 11:42 PM
  編輯帖子
快速美言
           


當前時區 GMT+8, 現在時間是 2024-11-23 12:22 PM

    Powered by Discuz!  © 2001-2007 Comsenz Inc.   
Processed in 1.540008 second(s), 8 queries

清除 Cookies - 聯繫我們 - LIPS Corner 新天藍 - Archiver