search
HomeWeb Front-endJS TutorialIntroduction to javascript time zone function_time and date

js time zone function:

Suppose datename is a created Date object

================ ====
datename.getTimezoneOffset()
--Get the difference between local time and GMT time (Greenwich Mean Time), the return value is in minutes
======== ============

Example: Get GMT time and time in any time zone based on local time

d=new Date(); //Create a Date object
localTime = d.getTime();
localOffset=d.getTimezoneOffset()*60000; //Get the number of milliseconds of local time offset
utc = localTime localOffset; //utc is GMT time
offset =10; //Take Hawaii time as an example, East District 10
hawaii = utc (3600000*offset);
nd = new Date(hawaii);
document.writeln("Hawaii time is " nd.toLocaleString()
");

============================
Date.UTC(year, month, day, hours, minutes, seconds, ms)

--Construct a Date object based on GMT time and return a Date object
============ ===================

Creating a Date object directly will assume that the input is local time, while creating an object using Date.UTC will assume that the input is GMT. Time

============================
datename.toUTCString()
datename.toGMTString( )
--Output GMT time
================================

The two functions are the same .The latter is considered obsolete.

Relative to toLocaleString outputs local time, this function outputs GMT time

================== ===========
Others
==============================

getUTCDate() function--returns the day of the month (1-31) in the date object expressed in Universal Coordinated Time (UTC)
getUTCDay() function--returns the day of the month expressed in UTC in the date object The day of the week represented (0-6)
getUTCFulYear() function--returns the four-digit year in the date object expressed in Universal Coordinated Time (UTC)
getUTCHours() function--returns the four-digit year in the date object expressed in UTC The number of hours in Universal Coordinated Time (UTC) (0-23)
getUTCMilliseconds() function--returns the number of milliseconds in the date object expressed in Universal Coordinated Time (UTC) (0-999)
getUTCMinutes() Function -- Returns the number of minutes (0-59) expressed in Universal Coordinated Time (UTC) in the date object
getUTCMonth() Function -- Returns the number of months (0-59) expressed in Universal Coordinated Time (UTC) in the date object 11)
getUTCSeconds() function -- returns the number of seconds in the date object expressed in Universal Coordinated Time (UTC) (0-59)


setUTCDate() function -- sets the date object The day of the month expressed in Universal Coordinated Time (UTC), and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970
setUTCFulYear() function -- sets the date object in world standard The year, month and day represented by time (UTC), and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970
setUTCHours() function --- Set the world standard in the date object Hours, minutes, seconds and milliseconds represented by time (UTC), and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970
setUTCMilliseconds() function--Set the world used in the date object The number of milliseconds expressed in standard time (UTC), and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970
setUTCMinutes() function--Set the date object using Universal Standard Time (UTC) ) represents the minutes and seconds, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970
setUTCMonth() function--Set the date object expressed in Universal Coordinated Time (UTC) Month, day, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970
setUTCSeconds() function--Sets the seconds and milliseconds in the date object expressed in Universal Coordinated Time (UTC) , and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

In the time zone in js, we generally talk about the time between Greenwich Time and local time The time difference is measured in minutes, which is no different from PHP and ASP. Let's use the date() function to introduce the related issues of js time zone.

Definition and Usage

The getTimezoneOffset() method returns the time difference between Greenwich Mean Time and local time, in minutes.
Syntax
dateObject.getTimezoneOffset() return value
The time difference between local time and GMT time, in minutes.
In the following example, we will get the time difference in minutes between GMT time and local time:

Copy code Code As follows:


Output:
-480
Let datename be a created Date object
================ ====
datename.getTimezoneOffset()
--Get the difference between local time and GMT time (Greenwich Mean Time), the return value is in minutes
======== ============

Example: Get GMT time and time in any time zone based on local time
Copy code The code is as follows:

d=new Date(); //날짜 객체 생성
localTime = d.getTime()
localOffset=d.getTimezoneOffset()*60000; 밀리초 수
utc = localTime localOffset; //utc는 GMT 시간입니다.
offset =10; //하와이 시간을 예로 들어 보겠습니다. 동부 10구역
hawaii = utc(3600000*offset); 🎜> nd = new Date(하와이);
document.writeln("하와이 시간은 " nd.toLocaleString()
");
Date.UTC(연, 월, 일, 시, 분 , 초, ms)
--GMT 시간을 기준으로 Date 객체를 구성하고 Date 객체를 반환합니다.

================== ====== =======
Date 객체를 직접 생성하면 입력이 현지 시간이라고 가정하고, Date.UTC를 사용하여 객체를 생성하면 입력이 GMT 시간이라고 가정합니다.
복사 코드는 다음과 같습니다
datename.toUTCString( )
datename.toGMTString()
--GMT 시간 출력
=================== =========
후자는 더 이상 사용되지 않는 것으로 간주됩니다.
toLocaleString과 관련하여 이 함수는

설명
getTimezoneOffset() 메소드는 현지 시간과 UTC 시간 사이의 분 수를 반환합니다. 기본적으로 이 함수는 JavaScript 코드가 실행되는 시간대와 지정된 시간이 일광 절약 시간제인지 여부를 알려줍니다. 🎜>반환이 시간이 아닌 분 단위로 이루어지는 이유. 일부 국가는 심지어 한 시간도 채 안 되는 시간대를 차지합니다.
팁 및 참고사항:
참고: 일광 절약 시간제 사용 관례로 인해 이 메소드의 반환 값은 상수가 아닙니다.
참고: The 메소드는 항상 Date 객체와 함께 사용됩니다.

var myDate=new Date()
Date 객체는 자동으로 저장됩니다.
매개변수 형식에는 다음과 같은 5가지 유형이 있습니다.


new Date("month dd,yyyy hh:mm :ss")
new Date("month dd,yyyy"); yyyy,mth,dd,hh,mm,ss);
new Date(yyyy,mth,dd) ;
new Date(ms)


마지막 형식에 유의하세요. 에서 매개변수는 생성되는 시간과 1970년 1월 1일 GMT 시간 사이의 밀리초 수를 나타냅니다. 다양한 함수의 의미는 다음과 같습니다.
month: 1월부터 12월까지 영어로 월 이름을 나타냅니다.
mth: (January)부터 11(December)까지, 월을 정수로 나타냅니다.
dd : 1부터 31까지의 일을 나타냅니다.
yyyy: 4자리 연도
hh: 시, 0(자정)부터 23(오후 11시)까지
mm: 분, 0의 정수 ~ 59
ss: 초 수, 0~59 사이의 정수
ms: 밀리초 수, 0보다 크거나 같은 정수
예:



코드 복사 코드는 다음과 같습니다. new Date("January 12,2006 22:19:35")
새 날짜("2006년 1월 12일");
새 날짜(2006,0,12,22,19,35)
새 날짜(2006,0,12); (1137075575000);


이전에는 js에도 시간대가 있다는 것을 몰랐습니다. 저는 항상 asp와 php에만 시간대가 있다고 생각했습니다. 도움이 필요한 학생들은 참고하시면 됩니다.
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Replace String Characters in JavaScriptReplace String Characters in JavaScriptMar 11, 2025 am 12:07 AM

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

Build Your Own AJAX Web ApplicationsBuild Your Own AJAX Web ApplicationsMar 09, 2025 am 12:11 AM

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

10 jQuery Fun and Games Plugins10 jQuery Fun and Games PluginsMar 08, 2025 am 12:42 AM

10 fun jQuery game plugins to make your website more attractive and enhance user stickiness! While Flash is still the best software for developing casual web games, jQuery can also create surprising effects, and while not comparable to pure action Flash games, in some cases you can also have unexpected fun in your browser. jQuery tic toe game The "Hello world" of game programming now has a jQuery version. Source code jQuery Crazy Word Composition Game This is a fill-in-the-blank game, and it can produce some weird results due to not knowing the context of the word. Source code jQuery mine sweeping game

How do I create and publish my own JavaScript libraries?How do I create and publish my own JavaScript libraries?Mar 18, 2025 pm 03:12 PM

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

jQuery Parallax Tutorial - Animated Header BackgroundjQuery Parallax Tutorial - Animated Header BackgroundMar 08, 2025 am 12:39 AM

This tutorial demonstrates how to create a captivating parallax background effect using jQuery. We'll build a header banner with layered images that create a stunning visual depth. The updated plugin works with jQuery 1.6.4 and later. Download the

Getting Started With Matter.js: IntroductionGetting Started With Matter.js: IntroductionMar 08, 2025 am 12:53 AM

Matter.js is a 2D rigid body physics engine written in JavaScript. This library can help you easily simulate 2D physics in your browser. It provides many features, such as the ability to create rigid bodies and assign physical properties such as mass, area, or density. You can also simulate different types of collisions and forces, such as gravity friction. Matter.js supports all mainstream browsers. Additionally, it is suitable for mobile devices as it detects touches and is responsive. All of these features make it worth your time to learn how to use the engine, as this makes it easy to create a physics-based 2D game or simulation. In this tutorial, I will cover the basics of this library, including its installation and usage, and provide a

Auto Refresh Div Content Using jQuery and AJAXAuto Refresh Div Content Using jQuery and AJAXMar 08, 2025 am 12:58 AM

This article demonstrates how to automatically refresh a div's content every 5 seconds using jQuery and AJAX. The example fetches and displays the latest blog posts from an RSS feed, along with the last refresh timestamp. A loading image is optiona

How do I optimize JavaScript code for performance in the browser?How do I optimize JavaScript code for performance in the browser?Mar 18, 2025 pm 03:14 PM

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.