How to convert a JavaScript date to UTC? Last Updated : 13 Dec, 2023 Comments Improve Suggest changes Like Article Like Report Javascript date can be converted to UTC by using functions present in the Javascript Date object. The toUTCString() method is used to convert a Date object into a string, according to universal time. The toGMTString() returns a string that represents the Date based on the GMT (UT) time zone. By default, JavaScript uses the browser’s time zone and displays a date as a full-text string: Fri Apr 12 2019 10:32:15 GMT+0530 (India Standard Time). To create a new Date object we use the javascript Date() constructor. Javascript Date Object Syntax:dateObj.toUTCString()Example 1: In this example, we are using the toUTCString() method. JavaScript let d = new Date(); let n = d.toUTCString(); console.log(n); OutputWed, 13 Dec 2023 06:40:12 GMT Example 2: In this example, we are using the toGMTString() method. JavaScript let d = new Date(); console.log(d.toGMTString()); OutputWed, 13 Dec 2023 06:40:00 GMT Comment More infoAdvertise with us Next Article How to convert a JavaScript date to UTC? P Pankaj_Singh Follow Improve Article Tags : JavaScript Web Technologies javascript-date Similar Reads How to Convert Date to Another Timezone in JavaScript? Converting a date to another timezone in JavaScript means adjusting the local date and time to match the time in a different timezone. This ensures that the displayed time aligns with the selected timezone, often using built-in methods or external libraries.1. Using Intl.DateTimeFormat() and format( 2 min read How to check if date is less than 1 hour ago using JavaScript ? Given a date and the task is to check whether the given date is less than 1 hour ago or not with the help of JavaScript. Approach 1: Count the milliseconds of the difference between the current and prev_date.If those are greater than milliseconds in 1 hour, then it returns false otherwise returns tr 2 min read How to check a date is valid or not using JavaScript? To check if a date is valid or not in JavaScript, we have to know all the valid formats of the date. For ex - "YYYY/DD/MM", "DD/MM/YYYY", and "YYYY-MM-DD", etc. We have a given date format and we need to check whether the given format is valid or not according to the official and acceptable date for 3 min read How to get the day and month of a year using JavaScript ? Given a date and the task is to get the day and month of a year using JavaScript. Approach: First get the current date by using new Date().Use getDay() method to get the current day in number format, Map it to the day name.Use getMonth() to get the current month in number format, Map it to the month 2 min read How to calculate the date three months prior using JavaScript ? To calculate the date three months prior using JavaScript, we could use the getMonth() and setMonth() methods. In this article, we are going to learn how to calculate the date three months prior using JavaScript. ApproachFirst, select the date object.Then use the getMonth() method to get the months. 1 min read How to calculate the yesterday's date in JavaScript ? In this article, we will see how to calculate yesterdayâs date in JavaScript. To calculate yesterday's date, you need to have some basic ideas of a few methods of JavaScript. JavaScript getDate() MethodJavaScript setDate() MethodJavaScript getDate() Method: It is an inbuilt JavaScript function that 3 min read How to calculate minutes between two dates in JavaScript ? Given two dates and the task is to get the number of minutes between them using JavaScript. Approach: Initialize both Date object.Subtract the older date from the new date. It will give the number of milliseconds from 1 January 1970.Convert milliseconds to minutes. Example 1: This example uses the c 2 min read How to get the first day of the year in JavaScript ? Given a date/year and the task is to get the first day of the year using JavaScript. Approach 1: Use getFullYear() Method to get the year from the given date.Use the new Date() function to create the new date object using year, month, and day. Example: This example uses the getFullYear() method to g 1 min read How to remove time from date using JavaScript ? Given a Date Object and the task is to remove the time portion from the object using JavaScript. JavaScript split() Method: This method is used to split a string into an array of substrings, and returns the new array. Syntax: string.split( separator, limit ) Parameters: separator: This parameter is 2 min read How to get the current date and time in seconds ? In this article, we will learn how to get the current date & time in seconds using JavaScript build-in methods. We will perform it in 2 ways: Using Date.now() methodUsing new Date.getTime() methodMethod 1: Using Date.now() MethodThe Date.now() method returns the number of milliseconds elapsed si 2 min read Like