• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

local time

New Here ,
Jan 30, 2007 Jan 30, 2007

Copy link to clipboard

Copied

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?
TOPICS
Advanced techniques

Views

538

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 30, 2007 Jan 30, 2007

Copy link to clipboard

Copied

Hi Ryan, you can use function "TimeFormat" like this :

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

Is it ok for you ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 30, 2007 Jan 30, 2007

Copy link to clipboard

Copied

but that will show the server time, not the local time of the persons computer?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 30, 2007 Jan 30, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 30, 2007 Jan 30, 2007

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 30, 2007 Jan 30, 2007

Copy link to clipboard

Copied

ok thanks Daverms, thats works

but now how do i use that to display ie

cfif am show morning cfelse show afternoon

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 30, 2007 Jan 30, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 30, 2007 Jan 30, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 30, 2007 Jan 30, 2007

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 30, 2007 Jan 30, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 30, 2007 Jan 30, 2007

Copy link to clipboard

Copied

Hi Dan

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

any ideas

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 30, 2007 Jan 30, 2007

Copy link to clipboard

Copied

LATEST
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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation