Solved

Changing timestamp formats

Posted on 2006-11-29
1
154 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
1 Comment
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to dynamically set the form action using jQuery.

743 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

12 Experts available now in Live!

Get 1:1 Help Now