Solved

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

Posted on 2010-09-11
4
442 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

837 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