Solved

Changing timestamp formats

Posted on 2006-11-29
1
160 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 500 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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 …
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:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 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