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 9192841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:01:31+00:00 2026-06-17T21:01:31+00:00

I am making a notification system which require the time since functionality. I am

  • 0

I am making a notification system which require the time since functionality.

I am using this script for timesince function(jQuery):

$.fn.updateSince = function(interval) {
    var times = this.map(function(){ return { e: $(this), t: parseInt($(this).html()) }; });

    var format = function(t) {
        if(t > 86400) {
            return Math.floor(t / 86400) + ' days ago';
        } else if (t > 3600) {
            return Math.floor(t / 3600) + ' hours ago';
        } else if (t > 60) {
            return Math.floor(t / 60) + ' minute ago';
        } else if (t > 50) {
            return '50 seconds ago';
        } else if (t > 40) {
            return '40 seconds ago';
        } else if (t > 30) {
            return '30 seconds ago';
        } else if (t > 25) {
            return '25 seconds ago';
        } else if (t > 15) {
            return '15 seconds ago';
        } else if (t > 10) {
            return '10 seconds ago';
        } else {
            return 'a few seconds ago';
        }
    }
    var update = function(){
        var now = new Date().getTime();
        $.each(times, function(i, o){
            o.e.html(format(Math.round((now - o.t) / 1000)));
        });
    };

    window.setInterval(update, interval);
    update();
    return this;
}

The notifications are stored in MySQL database , each notification has a timestamp on it that is in this format: 2012-12-26 06:21:28

I use PHP strtotime and change it into UTC format when obtaining the time out of the database for each notificaiton item:(php)

 $rows['time']= strtotime($temp_time." UTC");

When I pass it back to the client browser , using ajax. I will multiply the UTC time(from database) with 1000(javascript)

 var time = parseInt(dbtime * 1000);

Then I can use the jQuery timesince function to turn it into time ago.

Problem:
My server time varies with client browser time.
How do I make them “compatible” with each other.

For example , a notification is made 2 hours ago according to client browser.
But PHP says its made 7 hours ago.
because client browser timezone is different with my server’s

My logic is:
1. [PHP] Get current time , and use the notification time obtained from database to subtract with it.
database time – current time = time difference on server end

  1. [PHP] Then we get a time difference. in this case 7 hours.
  2. [PHP] How do i turn 7 hours into UTC format?
  3. [Javascript] Send the current client browser time , also in UTC format to php script.
  4. [PHP] client browser time – 7 hours(UTC?) = actual time of notification created for javascript use.
  5. [PHP] Send back the results to Javascript , so now the time can be 2 hours ago on client browser’s end.

How do I do this?

Just for info , UTC format is like(multiplied with 1000) : 1314952284779

  • 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-06-17T21:01:33+00:00Added an answer on June 17, 2026 at 9:01 pm

    Your logic could be:

    1. Convert the notification time to UNIX timestamp using strtotime (or any similar function)
    2. Use JavaScript Date function with this value (multiplied by 1000) to re-build the date
    3. Use (new Date) – thatDate to calculate the difference
    4. Convert to hours, minutes and seconds

    The problem I see here is in the first step. You mention that the dates are stored as 2012-12-26 06:21:28 but what timezone does this date correspond to? If it is the same time as the server timezone then using strtotime("2012-12-26 06:21:28") is sufficient to generate correct timestamp.

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

Sidebar

Related Questions

I am making a notification script and currently have this to display multiple notifications
i'm making a notification system, so that a user in a virtual community to
I'm having trouble making a div show up using javascript. <div class= notification success>
I am developing a system with Symfony which has a notification module integrated into
I am making a site with a notification system, on every page load AJAX
I'm making website that have notification 'button'. When user click this button, notification div
I am using local notifications in a app I'm making. I use this: Class
I'm making a weeapp for notification center using iOSOpenDev. I have a UITextField on
I'm interested in providing a general I'm making an ajax call notification ... similar
Making an adobe flex ui in which data that is calculated must use proprietary

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.