Javascript Change 1:06 Pm to 13.06.00
Javascript Change 1:06 Pm to 13.06.00: Converting time formats in JavaScript is a common task, especially when working with user input, databases, or UI widgets. One frequent requirement is converting 12-hour time (e.g., 1:06 PM) into a 24-hour format with dots, such as 13.06.00.
This guide explains how to perform this conversion clearly, efficiently, and using clean JavaScript.
Understanding the Time Format Conversion
The goal is to convert:
1:06 PM → 13.06.00
This transformation includes three steps:
-
Convert from 12-hour to 24-hour time
-
Format hours, minutes, and seconds
-
Replace separators with dots instead of colons
In JavaScript, this can be done using either built-in methods or manual string manipulation.
Using JavaScript’s Date Object for Conversion
One of the cleanest solutions is using the Date object.
Below is an example:
Why this works
-
JavaScript automatically interprets PM/AM.
-
padStartensures two-digit formatting. -
Dot-separated formatting is easy to apply.
Manual Conversion Without Using Date()
If you prefer to avoid using the Date object, you can convert the time manually:
Manual method benefits
-
Works in environments with limited Date support
-
Great for custom time parsers
-
More control over formatting
Using Intl.DateTimeFormat for Locale-Based Conversions
Modern JavaScript allows advanced time formatting using Intl.DateTimeFormat:
Why use Intl?
-
Handles formatting automatically
-
Supports multiple locales
-
Useful for apps requiring multilingual support
Common Mistakes to Avoid
When converting time formats in JavaScript, beware of:
1. Missing zero padding
Without padStart(2), results like 13.6.0 may occur.
2. Parsing times without AM/PM
JavaScript may misinterpret such strings as 24-hour format.
3. Local timezone issues
Always use a fixed date like 1970-01-01 to prevent unwanted timezone shifts.
4. Using invalid input formats
Make sure user input is always normalized before conversion.
Conclusion
Converting 1:06 PM into 13.06.00 in JavaScript is straightforward using built-in functions, manual logic, or international formatting tools. Whether you’re building a scheduling system, digital clock, log parser, or data transformation tool, these methods ensure accurate and clean time conversion.



