Solved

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

Posted on 2010-09-11
4
439 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
Comment Utility
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
Comment Utility
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
Comment Utility
"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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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.
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now