Solved

Changing timestamp formats

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
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 one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

632 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