Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Changing timestamp formats

Posted on 2006-11-29
1
Medium Priority
?
166 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 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

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
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:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

972 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