Front End Technology Articles

Page 521 of 652

How to get time difference between two timestamps in seconds?

Arushi
Arushi
Updated on 18-Jun-2020 3K+ Views

To get the time difference between two timestamps, try to run the following code. Here, we are calculating the total number of hours, minutes and seconds between two timestamps −ExampleLive Demo           JavaScript Dates                          var date1, date2;            date1 = new Date( "Jan 1, 2018 11:10:05" );          document.write(""+date1);          date2 = new Date( "Jan 1, 2018 08:15:10" );          document.write(""+date2);          var res ...

Read More

How to convert a Unix timestamp to time in JavaScript?

Smita Kapse
Smita Kapse
Updated on 18-Jun-2020 268 Views

To convert a Unix timestamp to time, you can try to run the following code in JavaScript −ExampleLive Demo           JavaScript Dates                        var unix_time = 1514791901 ;          var date = new Date(unix_time*1000);          // get hours          var hrs = date.getHours();          // get minutes          var min = "0" + date.getMinutes();          // get seconds          var sec = "0" + date.getSeconds();          document.write("Time- "+hrs + ":" + min.substr(-2) + ":" + sec.substr(-2));           OutputTime- 13:01:41

Read More

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

Abhinanda Shri
Abhinanda Shri
Updated on 18-Jun-2020 729 Views

To convert time in seconds, firstly get the current time. Then, multiply the hours to 3600 and minutes to 60; rest you can see below −(hours*3600) + (min*60) + secExampleYou can try to run the following code to get the current time in seconds −Live Demo           JavaScript Get Seconds                        var dt = new Date();          var sec = dt.getSeconds();          document.write("Seconds: " + sec);          var min = dt.getMinutes();          document.write("Minutes: " + min);          var hrs = dt.getHours();          document.write("Hours: " + hrs);          var total_seconds = (hrs*3600) + (min*60) + sec;          document.write("Total seconds: " + total_seconds) ;           OutputSeconds: 35 Minutes: 37 Hours: 9 Total seconds: 34655

Read More

How to compare two JavaScript Date Objects?

Ramu Prasad
Ramu Prasad
Updated on 18-Jun-2020 400 Views

To compare two date objects with JavaScript, create two dates object and get the recent date to compare it with the custom date.ExampleYou can try to run the following code to compare two dates −Live Demo                    var date1, date2;          date1 = new Date();          document.write(date1);          date2 = new Date( "Dec 10, 2015 20:15:10" );          document.write(""+date2);          if (date1 > date2) {             document.write("Date1 is the recent date.");          } else {             document.write("Date 2 is the recent date.");          }           OutputMon May 28 2018 09:48:49 GMT+0530 (India Standard Time) Thu Dec 10 2015 20:15:10 GMT+0530 (India Standard Time) Date1 is the recent date

Read More

What is the best way to initialize a JavaScript Date to midnight?

V Jyothi
V Jyothi
Updated on 18-Jun-2020 553 Views

To initialize a JavaScript Date to midnight, set hours like the following −setHours(0,0,0,0);ExampleYou can try to run the following code to set a date to midnight −Live Demo                    var dt;          dt = new Date();          dt.setHours(0,0,0,0);          document.write(dt);           OutputMon May 28 2018 00:00:00 GMT+0530 (India Standard Time)

Read More

HTML DOM Geolocation position property

AmitDiwan
AmitDiwan
Updated on 18-Jun-2020 217 Views

The HTML DOM Geolocation coordinates property is used for getting a user’s device position and altitude on earth. The user have to approve that he/she wants to give coordinates before this property could work. This is done so that users privacy isn’t compromised. This can be used for tracking various devices location.PropertiesFollowing is the position property −Note − The below properties are read-only −PropertyDescriptionposition.coordsTo return a coordinates object having information like latitude, longitude, altitude, and speed of the device on the earth. It also has an accuracy value describing how accurate the measurements are in meters.position.timestampTo representing the time and ...

Read More

How to get Natural logarithm of 2 in JavaScript?

Paul Richard
Paul Richard
Updated on 18-Jun-2020 539 Views

To get the Natural logarithm of 2, use the Math.LN2 property in JavaScript. It returns the natural logarithm of 2, which is approximately 0.693.ExampleYou can try to run the following code to get Natural logarithm of 2 −Live Demo           JavaScript Math LN2 Property                        var property_value = Math.LN2          document.write("Property Value is : " + property_value);           OutputProperty Value is : 0.6931471805599453

Read More

How to get Euler's constant value in JavaScript?

Kumar Varma
Kumar Varma
Updated on 18-Jun-2020 885 Views

To get Euler’s constant value in JavaScript, use the Math E property. This is a Euler's constant and the base of natural logarithms, approximately 2.718.ExampleYou can try to run the following code to get Euler’s constant value in JavaScript −Live Demo           JavaScript Math E Property                        var property_value = Math.E          document.write("Property Value is :" + property_value);           OutputProperty Value is :2.718281828459045

Read More

How to get the difference between two arrays in JavaScript?

Fendadis John
Fendadis John
Updated on 18-Jun-2020 325 Views

To get the difference between two arrays in JavaScript, try to run the following code. Here, we’re using some method like split(), indexOf(), sort(), etc to get the elements, which aren’t the same in both the arrays &mnus;ExampleLive Demo           JavaScript Dates                        function arrDifference (arr1, arr2) {             var arr = [];             arr1 = arr1.toString().split(', ').map(Number);             arr2 = arr2.toString().split(', ').map(Number);             // ...

Read More

How to preselect a value in a dropdown list of items in HTML forms?

Prabhas
Prabhas
Updated on 18-Jun-2020 6K+ Views

With HTML, you can easily create a simple drop down list of items to get user input in HTML forms. A select box also called drop down box provides an option to list down various options in the form of drop down list.You can also preselect a value in dropdown list of items in HTML forms. For that, add selected in the tag for the value you want to preselect.ExampleYou can try to run the following code to learn how to preselect value in a dropdown list of items works in HTML form −Live Demo       ...

Read More
Showing 5201–5210 of 6,517 articles
« Prev 1 519 520 521 522 523 652 Next »
Advertisements