11 Replies Latest reply on Jan 30, 2007 7:42 PM by

    local time

    RyanG24 Level 1
      Hi can i show the word morning or afternoon, if the local time is before or after 12:00 ?

      can you do this using the computers local time?
        • 1. Re: local time
          Jack987
          Hi Ryan, you can use function "TimeFormat" like this :

          <cfoutput>#TimeFormat(now(), "hh:mm:ss tt")#</cfoutput>

          Is it ok for you ?
          • 2. Re: local time
            azadisaryev Level 1
            TimeFormat(now(), "hh:mm:ss") will only format current SERVER time, which is not necessarily same as USER's time.

            Look up LS functions in CF (LSTimeFormat, LSParseDateTime, etc) and SelLocale.
            • 3. Re: local time
              RyanG24 Level 1
              but that will show the server time, not the local time of the persons computer?
              • 4. Re: local time
                Daverms Level 3
                Try this..

                <script language="javascript">
                function getTime()
                {
                var s=new Date();
                var hrs=s.getHours();
                var mins=s.getMinutes();
                var secs=s.getSeconds();
                var session=""
                if (hrs > "12")
                {
                session="PM";
                }
                else
                {
                session="AM";
                }
                alert(hrs+":"+mins+":"+secs+" "+session);
                }
                </script>

                <body onload="getTime()">
                </body>
                • 5. Re: local time
                  Level 7
                  Sabaidee wrote:
                  > Look up LS functions in CF (LSTimeFormat, LSParseDateTime, etc) and SelLocale.

                  well that won't show you the user's time either ;-) just their localized version
                  of the server (or whatever) time.

                  • 6. Re: local time
                    RyanG24 Level 1
                    ok thanks Daverms, thats works

                    but now how do i use that to display ie

                    cfif am show morning cfelse show afternoon
                    • 7. Re: local time
                      Dan Bracuk Level 5
                      Set up a div or span or something like that. Then call the js as a body onload event, as Davern's suggested. Add something to the js function to update the value of your div or span with the current time.

                      If you want to get fancy, you can update it every minute or so.
                      • 8. Re: local time
                        RyanG24 Level 1
                        Hi thanks Dan,

                        but i am just not sure how to do this, do i need to use the cfif tag?

                        as i need to show Morning or Afternoon
                        • 9. Re: local time
                          Dan Bracuk Level 5
                          Don't mix cold fusion with javascript. You already have most of the function. You just have to display the results.

                          Google "Javascript display time" for code samples.
                          • 10. Re: local time
                            RyanG24 Level 1
                            Hi Dan

                            i have searched google but cant find how to do it?

                            any ideas
                            • 11. local time
                              Here.

                              <html>
                              <script language="javascript">

                              function startTimer() {
                              setInterval('showTime()', 1000);
                              }

                              function showTime() {

                              var s=new Date();
                              var hrs=s.getHours();
                              var mins=s.getMinutes();
                              var secs=s.getSeconds();
                              var session=""
                              if (hrs > "12")
                              {
                              session="Afternoon";
                              }
                              else
                              {
                              session="Morning";
                              }
                              document.getElementById('output').innerHTML = hrs + ":" + mins + ":" + secs + " " + session;
                              }

                              </script>
                              <body onload="startTimer();">
                              <span id="output"></span>
                              </body>
                              </html>