Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 893063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:09:32+00:00 2026-05-15T14:09:32+00:00

How can I manipulate dates so that they show up as just now… 5

  • 0

How can I manipulate dates so that they show up as “just now”… “5 mins ago”… “3 hours ago”… “June 22nd, 2010 at 1:45pm” in similar fashion to how SO displays the dates next to the answers/comments to each question?

To further complicate matters, the dates stored in my database are in GMT time (which is fine), but I want them to appear in the timezone of each user’s browser.

I’ve already tried John Resig’s pretty date plugin: http://bassistance.de/jquery-plugins/jquery-plugin-prettydate/, and I’ve edited it so that it subtracts the timezone offset from the GMT time in the database. However, this solution only works in FireFox.

Here’s the ‘prettydate’ function after I’ve added the timezone offset:

format : function(time) {
var date = new Date(time);
var currentDate = new Date();
var timezoneOffsetInMilliseconds = currentDate.getTimezoneOffset() * 60000;
var currentTimeInMillisecondsUtc = currentDate.getTime();
var givenTimeInMillisecondsUtc = date.getTime()- timezoneOffsetInMilliseconds;
var diffInSeconds = ((currentTimeInMillisecondsUtc - givenTimeInMillisecondsUtc) / 1000);
var day_diff = Math.floor(diffInSeconds / 86400);

if (isNaN(day_diff) || day_diff < 0)
    return;

        // If longer than a month, calculate the date w/ timezone offset
        if (day_diff >= 31)
            return new Date(givenTimeInMillisecondsUtc).toLocaleString();

        var messages = $.prettyDate.messages;
        return day_diff == 0 && (diffInSeconds < 60 && messages.now 
            || diffInSeconds < 120 && messages.minute
             || diffInSeconds < 3600
             && messages.minutes(Math.floor(diffInSeconds / 60))
            || diffInSeconds < 7200 && messages.hour || diffInSeconds < 86400
            && messages.hours(Math.floor(diffInSeconds / 3600)))
            || day_diff == 1 && messages.yesterday || day_diff < 7
            && messages.days(day_diff) || day_diff < 31
            && messages.weeks(Math.ceil(day_diff / 7));
    }

Edit:
I’m using Python with Django templates (via Google Webapp), and the ‘time’ object I’m passing in a ‘db.DateTimeProperty()’ in the iso format like so:

<span class="prettyDate" title='{{ q.date.isoformat }}'>{{q.date.isoformat}}</span>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:09:33+00:00Added an answer on May 15, 2026 at 2:09 pm

    Why not do this server-side, with the built-in template tag timesince, or a custom template tag?

    In relative time, there is not meaning to timezones, as long the 2 times you are diffing are in the same zone. For the results that are farther away in the past, and you want to present as absolute times, you’ll have to do the time shift yourself. for this, you’ll have to ask the user for her timezone (or use some JS on a previous page to send it to you) and store it in the user profile.

    this is also discussed in the mailing list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I set this up so that I can manipulate $backgroundcolor = #00FFFF;
How can I manipulate using JavaScript (JQuery) a site, not in my server, that
Can you recommend efficient/clean way to manipulate arbitrary length bit array? Right now I
Javascript can manipulate the document the browser is displaying, so the following: <script> document.write(<table><tr><td>Hola</td><td>Adios</td></tr></table>);
I have situation where a user can manipulate a large set of data (presented
I have an interactive web application powered by jQuery where users can manipulate visual
How can I manipulate the jquery tab, for example when a submit form is
Afaik, you can change/manipulate browser settings in Mozilla/Netscape browsers. For Instance netscape.security.PrivilegeManager.enablePrivilege('someprivilege'); Of course
I need to write an app which can observe and manipulate the positions of
Is there a way to manipulate movies in iphone in a way I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.