Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
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…

749 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