Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date format displays wrong

Status
Not open for further replies.

kiwieur

Technical User
Apr 25, 2006
200
GB
Hi,

I am using the following script to display local time for 5 different countries.

Code:
<script type="text/javascript">

/***********************************************
* Local Time script- © Dynamic Drive ([URL unfurl="true"]http://www.dynamicdrive.com)[/URL]
* This notice MUST stay intact for legal use
* Visit [URL unfurl="true"]http://www.dynamicdrive.com/[/URL] for this script and 100s more.
***********************************************/

var weekdaystxt=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
var months=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

function showLocalTime(container, servermode, offsetMinutes, displayversion){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.displayversion=displayversion
var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'
this.localtime=this.serverdate=new Date(servertimestring)
this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time
this.updateTime()
this.updateContainer()
}

showLocalTime.prototype.updateTime=function(){
var thisobj=this
this.localtime.setSeconds(this.localtime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

showLocalTime.prototype.updateContainer=function(){
var thisobj=this
if (this.displayversion=="long")
this.container.innerHTML=this.localtime.toLocaleString()
else{
var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()
var ampm=(hour>=12)? "PM" : "AM"
var currentdate=this.localtime.getDate()
var year=this.localtime.getFullYear()
var dayofweek=weekdaystxt[this.localtime.getDay()]
var date=months[this.localtime.getMonth()]
//this.container.innerHTML=" "+dayofweek+" "+formatField(hour, 1)+":"+formatField(minutes)+""+ampm+" "+dayofweek+" "
this.container.innerHTML=""+dayofweek+", "+currentdate+" "+date+" "+year+" "+formatField(hour, 1)+":"+formatField(minutes)+" "+ampm+" "
}
setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
}

function formatField(num, isHour){
if (typeof isHour!="undefined"){ //if this is the hour field
var hour=(num>12)? num-12 : num
return (hour==0)? 12 : hour
}
return (num<=9)? "0"+num : num//if this is minute or sec field
}

</script>

However no matter what i do it always displays in US format. I have the testing server and my local PC set to GB settings I have also added the following session LCID to the page

Code:
<% '***Start Session ID Code and Sets the server locale
session.LCID = 2057
'***End Session ID Code
%>

can anyone help me sort this out please


Regards

Paul
 
What format do you get if you simply have:
Code:
today = new date()
this.container.innerHTML=""+today
?

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Not possitive but I think
var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'

is you problem this is like an if statment in vb
if servermode="server-php do the following : else bla

I don't know why you would use this, rather than the date functions in javascript which gets the users local settings.
 
traingamer,

sorry can you explain a little please i am a real newbie where javascript is concerned. I do try to solve things on my own by looking on the net, but i am not sure what you are asking me to do

Regards

Paul

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top