?
Solved

Changing timestamp formats

Posted on 2006-11-29
1
Medium Priority
?
164 Views
Last Modified: 2010-04-06
Hello,
How can I format a timestamp from this: 11/27/2006 2:56:03 PM, to where it reads: Posted X Days, Y Hours Ago.

Is there a simple javascript function that will do that?  I receive the timestamp as a JSON object and am pretty sure its a string, but it could be a DATE/TIME Format.  thanks!
0
Comment
Question by:kevinmeredith
[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
1 Comment
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 18039919
var d = new Date(timeStamp)
var now = new date()
anHour = 60*60*1000;
aDay = anHour*24
var diff =(now.getTime()-d.getTime())

var diffInHours = diff%aDay; //
var days = parseInt(diff/aDay)
document.write('posted '+days+((days==1)?"":"s")+", "+diffInHours+((diffInHours==1)?"":"s")+" ago")
0

Featured Post

Independent Software Vendors: 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

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

719 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