Displaying the last time a post was updated, similar to the notification system used on

In my development work, I often utilize momentJs to calculate the time difference between now and a specific date. Here is an example of how I use it:

moment([MyDate]).fromNow();

This code typically returns results such as:

"a few minutes ago" or "10 hours ago" ...

I once attempted to tweak the code to display the difference in seconds like so:

moment([MyDate]).fromNow().asSeconds();

Unfortunately, this adjustment didn't yield the desired outcome.

As a solution, I am interested in creating functionality similar to Twitter's last update notification. Any suggestions on how best to achieve this?

Answer №1

To calculate the difference in seconds between two dates, use the following code snippet: moment().diff(mydate, 'seconds')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble resolving the templateUrl for AngularJS in a shared module

It's really frustrating me. I have an angular module that is injected into different apps. Whenever I attempt to use templateUrl with a relative path in the shared module, it throws a 404 error. angular.min.js:99 GET http://localhost:8001/modals/mo ...

The style from 'http://localhost:2000/cssFile/style.css' was rejected because its MIME type was 'text/html'

Currently, I am attempting to include my style.css file in the home.ejs file being rendered by express.js. However, I keep encountering the following error: Refused to apply style from 'http://localhost:2000/cssFile/style.css' because its MIME t ...

Updating form validation by altering input value

I'm currently utilizing JavaScript regular expressions for form validation in my project. After successfully completing the validation without any errors, upon clicking the submit button, I want the form to be submitted and change the submit value to ...

Preventing a Page from Refreshing on Function Call in React

I'm facing an issue with calling a function to retrieve data from an API and display it. Every time I invoke this function, the page refreshes and the state gets reset, causing the page to show nothing. Within a child component, there is an input box ...

AngularJS: Sending form data to an external server results in an error due to restricted URI access

I am currently diving into the world of AngularJs and putting effort into mastering it. In this process, I've created a demo application that attempts to send form data to a localhost site. The code for this endeavor is provided below. index.html &l ...

Utilizing the keyword 'this' within a function of a JavaScript class that is invoked with the .map method

I am working with the RegisterUser class which contains various methods and properties: class RegisterUser { constructor(username, password, ispublic){ this.username = username; this.password = password; this.ispublic = ispublic; this.id ...

The request for `/` cannot be fulfilled while serving an Angular application with Express and Node.js

I've been attempting to host an Angular application using Node.js, but I keep encountering the error message "Cannot GET /" displayed on the page. Despite trying various solutions, I have been unable to resolve this issue. Does anyone have any suggest ...

The method being spied on by Sinon has not been called

Testing the code involves a simple process: it triggers a method based on a certain condition. If the condition is not met, another method from within the first one is triggered as an attribute. app.js: function test (fn, isActivated) { if (isActivat ...

Utilizing Express JS to keep users on the same page upon submitting a form

Although this may seem like a simple query with available tutorials, I am struggling to locate the specific information. I utilized express-generator to create an app and included a basic form in a route. views/form.ejs <div> <h1>This is < ...

Rotate an image based on the movement of the mouse cursor

The following code snippet demonstrates how to rotate an image element using jQuery: $(document).ready(function(){ var player = $('#player'); $(window).on('mousemove', function (e) { var p1 = { x: playe ...

What is the process for configuring environmental variables within my client-side code?

Is there a reliable method to set a different key based on whether we are in development or production environments when working with client-side programs that lack an inherent runtime environment? Appreciate any suggestions! ...

The collapsible navbar feature is malfunctioning and the navbar-toggle button is not responsive

Whenever I reduce the size of my browser, the collapsible navbar in Bootstrap is not visible. This is the code for my webpage: index.html <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv=" ...

Using Vue: How to utilize v-slot variables in JavaScript

Can the values of the v-slot of a component be accessed in the script? For instance, consider the following template: <cron-core v-model="value" :periods="periods" :format="format" v-slot="{fields, period, error}"> {{period}} <div v-for="fiel ...

Development and staging setups tailored specifically for a JavaScript SDK

Currently, I am working with a Javascript SDK that is available on NPM. Alongside this, I have a Vue application utilizing the SDK and it's crucial for me to test them together across various pre-production environments (such as staging). Here are the ...

Unable to modify the content inside an HTML object using an anchor tag

I am currently working on a project for a client who wants to integrate three websites into a single browser window, allowing them to interact without opening multiple windows. Originally, I thought using iframes would solve the issue, but unfortunately, t ...

Error: The specified object does not contain the 'tableRow' method

I am currently working on a contacts book project and I need a table to update as the user inputs data. However, I keep encountering an error related to 'tableRow'. I have tried changing function names and other solutions but haven't been ab ...

How to update a boolean value in a JSON object using AngularJS?

Trying to modify a boolean value when a user clicks on a JSON-populated table row. Here's an example of the setup... $scope.prices = { "Prices": [ { "Code": "edl", "Selected": false }, { "Code": "ead", "Sel ...

The database powered by Postgresql performs flawlessly when it comes to updating data with accurate code execution. However, there seems to be an

Imagine a zoo with a postgresql database. To enable web access to this database, I am using php and javascript. Most of the web pages are working fine, but I am currently working on a page where clients can add or remove animals from existing exhibits. T ...

turning off next.js server side rendering in order to avoid potential window is undefined issues

I am currently managing a private NPM package that is utilized in my Next.js project, both of which are React and Typescript based. Recently, I integrated a graph feature into the NPM package and encountered an issue where any reference to window within t ...

Set a generic function type to a variable

Currently, I am facing an issue where I have a declared function type with generics that I want to assign to a named arrow function. Below is an example of the code: import { AutocompleteProps } from '@material-ui/lab/Autocomplete'; const itemTo ...