Solved

Javascript MM:dd:hh:mm:ss counter using server time date rather than client

Posted on 2010-09-11
4
441 Views
Last Modified: 2012-05-10
Hi,
I am tasked with creating a countdown to a specific event online. I need the countdown to use the Server Side Date/Time rather than the local Date/Time

The format of the counter is Months:Days:Hours:Minutes:Seconds

I need to format the output using CSS styles

I have found some examples online but either they are using the local machine time via a javascript .getTime() statement or they are an incredibly verbose solution incorporating debugs and all sorts of options simply not required.

Whilst it will be possible to pull the bones out of one of these solutions Javascript is not exactly my strongest disciplines and it is going to be a long old process.

I am sure someone has a neat and simple solution which uses clear and concise code.

Thanks in advance
0
Comment
Question by:splanton
4 Comments
 
LVL 11

Accepted Solution

by:
madgino earned 167 total points
ID: 33654140
Use javascript but initialize the start date with the datetime from the server:
var date_time = '<%=Now()%>';

Or use date() or time() or whatever you need.
0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 167 total points
ID: 33654368
And plug it into one of the million simple countdown scripts

http://www.google.com/search?q=simple+javascript+countdown
0
 
LVL 3

Assisted Solution

by:timhigham
timhigham earned 166 total points
ID: 33658245
"someone has a neat and simple solution"
"it is going to be a long old process" - Agreed

I worry (not critise) about your admission of required Javascript knowledge deficit.
For all webpages Javascript code is downloaded from the server and started and run on the local machine. Therefore it will never have server data - IN THEORY.
You have no option but to research for example Javascript, server code such as PHP or AJAX.
Which one depends on your requirements.
I recommend PHP.

You can write lines into the page Javascript values into which you can 'drop in' the server values via PHP 'echo' statement' - it will fill in required values which the browser will interpret as the same.

E.G:
Where yyou write into a simple webpage:
<script type="javascript">
     var timestamp=now();
</script>

PHP would drop in the server value

<script type="javascript">
     var timestamp=<?php echo serversidetimestamp ?>;
</script>
0
 
LVL 2

Author Closing Comment

by:splanton
ID: 33680633
I was hoping for an example working solution rather than an out of context example, but still never mind eh.

Got it working in the end took me some time though.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question