Get the current UTC Date and Time using JavaScript
A time zone is designated region or area on Earth which is also the localized time for standardization and regulated for the
sake of coordination with time zone of other places. It adds simplicity in localization of the time with respect to
GMT time
The concept of time zones was emerged in late 19th century, It was emerged to address the confusion on varying local time.
Before the establishment of time zone, each city or town has their own time based on the position of the sun which made
scheduling and coordinating the various activities challenging across different locations.
Time zones are aligned with meridians of longitude. Each zone covers approximately 15 degrees of longitude.
The starting point for time zone is at 0 degrees longitude which is also called Prime Meridian. It pass through
Greenwich, London, England. The timezone increase or decrease by one hour moving eastward or westward from the Prime Meridian.
Some of the countries like China and India have disregard the multiple theoretical timezone and have opted a single time zone across their entire territory
Using Coordinated Universal Time (UTC) in applications serves several crucial purposes:
-
Standardization: UTC provides a globally recognized standard for timekeeping. It helps maintain
consistency and facilitates communication and synchronization across different systems and locations worldwide.
-
Avoiding Timezone Issues: UTC does not have timezone offsets, making it ideal for applications that operate across
different time zones. By using UTC as a reference point, applications can avoid confusion and errors related to daylight
saving time changes, timezone conversions, and regional variations.
-
Synchronization: UTC does not have timezone offsets, making it ideal for applications that operate across
different time zones. By using UTC as a reference point, applications can avoid confusion and errors related to daylight
saving time changes, timezone conversions, and regional variations.
- Avoiding Timezone Issues: UTC serves as a common reference point for synchronizing distributed systems,
databases, logs, and events. Using UTC timestamps ensures that events are accurately sequenced and coordinated regardless of the geographical
location or local time settings of individual components.
-
Avoiding Timezone Issues: UTC does not have timezone offsets, making it ideal for applications that operate across
different time zones. By using UTC as a reference point, applications can avoid confusion and errors related to daylight
saving time changes, timezone conversions, and regional variations.
-
Accuracy and Precision: UTC timekeeping is highly accurate and precise, maintained by international timekeeping
standards such as atomic clocks. This reliability is crucial for applications that require precise timing, such as
financial transactions, scientific experiments, and network protocols.
-
Consistency in Data Storage and Exchange: Storing and exchanging timestamps in UTC format simplifies data management and
interoperability. It eliminates the need for complex timezone conversions and ensures that timestamps remain consistent
and unambiguous across different platforms, databases, and applications.
-
Compliance and Regulations: In certain industries and applications, adherence to standardized timekeeping practices,
such as using UTC, is required by regulations, compliance standards, or industry best practices. Using UTC helps ensure
compliance with these requirements.
-
Facilitating Global Collaboration: For applications involving distributed teams, partners, or customers spanning
multiple time zones, using UTC promotes collaboration and coordination by providing a common reference for scheduling
meetings, deadlines, and other time-sensitive activities.
const now = new Date();
const year = now.getUTCFullYear();
const month = ('0' + (now.getUTCMonth() + 1)).slice(-2);
const day = ('0' + now.getUTCDate()).slice(-2);
let hours = ('0' + now.getUTCHours()).slice(-2);
const minutes = ('0' + now.getUTCMinutes()).slice(-2);
const seconds = ('0' + now.getUTCSeconds()).slice(-2);
const ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12;
const final_date_time = `${year}-${month}-${day} ${hours}:${minutes}:${seconds} ${ampm}`