Solved

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

Posted on 2010-09-11
4
450 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
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 …

705 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