Front End Technology Articles

Page 340 of 652

How can I get time and date since epoch in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 5K+ Views

In this tutorial, we will learn to get the date and time since epoch in JavaScript. Sometimes, programmers need to find the total number of milliseconds, seconds, days, or other time units from 1 January 1970 since the UNIX epoch started. The Unix epoch is the starting point (January 1, 1970, 00:00:00 UTC) used by most computer systems to measure time. JavaScript provides several methods to calculate time elapsed since this date. Using the Date() Constructor In this approach, we will learn to get the current date from the UNIX epoch that started on 1 January 1970. ...

Read More

How to convert epoch Date to meaningful JavaScript date?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 20K+ Views

In this tutorial, we will learn to convert the epoch Date to a meaningful JavaScript date. The epoch date is a representation of the date in milliseconds, and it is a total number of milliseconds since 1st January 1970 since the UNIX epochs started. Users can convert the total number of milliseconds into the meaningful date string using various approaches explained below. Using the new Date() Object In this approach, we will create the object of the Date class. The constructor of the Date() class takes the total number of milliseconds since the epoch started and converts ...

Read More

How to compare only date part without comparing time in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 7K+ Views

While developing applications, you often need to compare only the date parts of two Date objects, ignoring the time components. For example, in a subscription system, you might want to check if a user's payment was made on or before the subscription deadline, regardless of what time the payment was processed. In this tutorial, we will learn to compare only the date part without comparing the time in JavaScript. Using the setHours() Method The most straightforward approach is to set the time components (hours, minutes, seconds, milliseconds) to zero for both date objects. This ensures that when ...

Read More

How to compare two JavaScript Date Objects?

Ramu Prasad
Ramu Prasad
Updated on 15-Mar-2026 423 Views

JavaScript Date objects can be compared directly using comparison operators (>, =, date2) { document.write("Current date is more recent."); } else { document.write("Custom date is more recent."); } Current date: Mon May 28 2018 09:48:49 GMT+0530 (India Standard Time) Custom date: Thu Dec 10 2015 20:15:10 GMT+0530 (India Standard Time) Current date is more recent. Comparing for ...

Read More

How to convert a date object to string with format hh:mm:ss in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 10K+ Views

We will learn to convert the date object to a string with the format hh:mm:ss in JavaScript. Working with dates and times is common in web development, and formatting them according to specific requirements is an essential skill. The default date object returns a complete date string, which might contain more information than needed. Here, we will explore different approaches to extract and format just the time portion in hh:mm:ss format. Using toTimeString() Method The toTimeString() method returns the time portion of a Date object as a human-readable string. We can then extract the first 8 characters ...

Read More

How do I subtract minutes from a date in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 6K+ Views

In this tutorial, we will learn to subtract minutes from a date in JavaScript. Working with dates is a common requirement in web development, and JavaScript provides built-in Date class methods to handle date manipulations effectively. We'll explore three approaches: using native JavaScript methods getMinutes() and setMinutes(), working with milliseconds, and using the Moment.js library for more convenient date operations. Using the getMinutes() and setMinutes() Methods This approach uses the Date object's built-in methods to extract current minutes, subtract the desired amount, and update the date object. Syntax let date = new Date(set_date); let ...

Read More

How to get time difference between two timestamps in seconds?

Arushi
Arushi
Updated on 15-Mar-2026 3K+ Views

To get the time difference between two timestamps in seconds, you can subtract one Date object from another and divide by 1000. JavaScript Date objects return milliseconds when subtracted, so dividing by 1000 converts to seconds. Basic Time Difference in Seconds The simplest approach is to subtract two Date objects and convert milliseconds to seconds: Time Difference in Seconds var date1 = new Date("Jan 1, 2018 11:10:05"); ...

Read More

How to get current date/time in seconds in JavaScript?

Abhinanda Shri
Abhinanda Shri
Updated on 15-Mar-2026 792 Views

To get the current time in seconds in JavaScript, you can extract hours, minutes, and seconds from a Date object and convert them to total seconds using the formula: (hours * 3600) + (minutes * 60) + seconds Method 1: Converting Current Time to Seconds This approach gets individual time components and calculates total seconds since midnight: JavaScript Get Seconds ...

Read More

How to get the number of seconds between two Dates in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 21K+ Views

In JavaScript, calculating the difference between two dates in seconds is a common requirement for timers, age calculators, and duration displays. JavaScript Date objects provide millisecond precision, which we can easily convert to seconds. Using the getTime() Method The getTime() method returns the number of milliseconds since January 1, 1970 UTC. By subtracting two timestamps and dividing by 1000, we get the difference in seconds. Syntax let date1 = new Date("Aug 12, 2022 19:45:25"); let date2 = new Date("Aug 14, 2022 19:45:25"); let seconds = Math.abs(date1.getTime() - date2.getTime()) / 1000; Example ...

Read More

How to convert a MySQL date to JavaScript date?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 8K+ Views

In this tutorial, we will learn to convert the MySQL date to JavaScript date. The MySQL date is not different from the regular date, but its format or syntax is different, which we need to convert into the format of a normal date. The general syntax of the MySQL date is YYYY-MM-DD HH:mm:ss. So, we need to convert the given MySQL date string syntax to normal date syntax. We will have two approaches to converting the MySQL date to the JavaScript date. Using the replace() Method Using the split() Method ...

Read More
Showing 3391–3400 of 6,519 articles
« Prev 1 338 339 340 341 342 652 Next »
Advertisements