Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 297 of 534
How to get time difference between two timestamps in seconds?
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 MoreIndent the first line of a paragraph in CSS
Use the text-indent property to indent the first line of a paragraph. This property accepts values in pixels (px), centimeters (cm), percentages (%), or em units. Syntax text-indent: value; Parameters The text-indent property accepts the following values: Length values: px, em, cm, mm, in, pt, pc Percentage: Relative to the width of the containing block Keywords: inherit, initial, unset Example: Basic Text Indentation You can try to run the following code to indent the first line: ...
Read MoreHow to get current date/time in seconds in JavaScript?
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 MoreUsage of border property with CSS
The border property in CSS is used to create visible borders around HTML elements. It's a shorthand property that combines border width, style, and color in a single declaration. Syntax border: width style color; Where: width - thickness in pixels, ems, or other units style - solid, dashed, dotted, double, etc. color - any valid CSS color value Example: Basic Border Usage Here's how to apply different border styles to images: ...
Read MoreHow to get the number of seconds between two Dates in JavaScript?
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 MoreHow to convert a MySQL date to JavaScript date?
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 MoreHow to get the difference between two arrays in JavaScript?
To get the difference between two arrays in JavaScript, you can find elements that exist in one array but not in both. This is commonly called the symmetric difference. There are several approaches to achieve this. Using filter() and includes() (Recommended) Array Difference function arrayDifference(arr1, arr2) { // Elements in ...
Read MoreChange the color of right border with CSS
The border-right-color CSS property allows you to change the color of an element's right border specifically, without affecting the other borders. Syntax border-right-color: color; Parameters The color value can be specified using: Color names: red, blue, green Hex values: #FF0000, #00FF00 RGB values: rgb(255, 0, 0) HSL values: hsl(0, 100%, 50%) Example: Basic Right Border Color .demo { border: 3px solid black; ...
Read MoreHow to get the value of PI in JavaScript?
In this tutorial, we will learn how to get the value of PI in JavaScript. The PI is a mathematical constant that is widely used in different sections of mathematics. It is defined by the ratio of the circumference of a circle to its diameter, which is approximately 3.14159. It is represented by the symbol '𝜋', which is a Greek letter. The value of PI is an irrational number, which means the value of the PI can't be expressed as a fraction, and the digits that came after the decimal are non-terminating and non-repeating. The value ...
Read MoreHow to get the arccosine (in radians) of a number in JavaScript?
This tutorial will help you to find the arccosine in radians of a number in JavaScript. Cosine is the ratio of the adjacent side and the hypotenuse of the right-angled triangle. To get the cosine of a number, the Math.cos() function is used in JavaScript. The value returned will be between -1 and 1. The inverse of cosine is called arccosine. An angle's trigonometric arccosine value can be calculated using the Math.acos() method. This returns a value between 0 and π (pi). The input to acos() must be between -1 and 1 inclusive. The function returns the ...
Read More