Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

Basic JavaScript

JS Tutorial JS Introduction JS Where To JS Output

JS Syntax

JS Syntax JS Statements JS Comments JS Variables JS Let JS Const JS Types

JS Operators

JS Operators JS Arithmetic JS Assignment JS Comparisons JS Conditional JS If JS If Else JS Ternary JS Switch JS Booleans JS Logical

JS Loops

JS Loops JS Loop for JS Loop while JS Break JS Continue JS Control Flow

JS Strings

JS Strings JS String Templates JS String Methods JS String Search JS String Reference

JS Numbers

JS Numbers JS Number Methods JS Number Properties JS Number Reference JS Bitwise JS BigInt

JS Functions

Function Path Function Intro Function Invocation Function Parameters Function Returns Function Arguments Function Expressions Function Arrow Function Quiz

JS Objects

Object Path Object Intro Object Properties Object Methods Object this Object Display Object Constructors

JS Scope

JS Scope JS Code Blocks JS Hoisting JS Strict Mode

JS Dates

JS Dates JS Date Formats JS Date Get JS Date Set JS Date Methods

JS Arrays

JS Arrays JS Array Methods JS Array Search JS Array Sort JS Array Iterations JS Array Reference JS Array Const

JS Sets

JS Sets JS Set Methods JS Set Logic JS Set WeakSet JS Set Reference

JS Maps

JS Maps JS Map Methods JS Map WeakMap JS Map Reference

JS Iterations

JS Loops JS Iterables JS Iterators JS Generators

JS Math

JS Math JS Math Reference JS Math Random

JS RexExp

JS RegExp JS RegExp Flags JS RegExp Classes JS RegExp Metachars JS RegExp Assertions JS RegExp Quantifiers JS RegExp Patterns JS RegExp Objects JS RegExp Methods

JS Data Types

JS Destructuring JS Data Types JS Primitive Data JS Object Types JS typeof JS toString JS Type Conversion

JS Errors

JS Errors Intro JS Errors Silent JS Error Statements JS Error Object

JS Debugging

Debugging Intro Debugging Console Debugging Breakpoints Debugging Errors Debugging Async Debugging Reference

JS Conventions

JS Style Guide JS Best Practices JS Mistakes JS Performance

JS References

JS Statements JS Reserved Keywords JS Operators JS Precedence

JS Versions

JS 2026 JS 2025 JS 2024 JS 2023 JS 2022 JS 2021 JS 2020 JS 2019 JS 2018 JS 2017 JS 2016 JS Versions JS 2015 (ES6) JS 2009 (ES5) JS 1999 (ES3) JS IE / Edge JS History

JS HTML

JS HTML DOM JS Events JS Projects New

JS Advanced

JS Temporal  New JS Functions JS Objects JS Classes JS Asynchronous JS Modules JS Meta & Proxy JS Typed Arrays JS DOM Navigation JS Windows JS Web APIs JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Reference


JavaScript Temporal PlainTime

The PlainTime Object

The Temporal.PlainTime object is a time object without a date.

It represents an ISO 8601 wall-clock time without a date or time zone.

Example: 10:30:00.

It is useful for opening hours, alarms, and any time-only values.

The Temporal.PlainTime Object

The Temporal PlainTime object is a time object with no date.

It represents an ISO 8601 wall-clock time without a date or time zone.

Example: 14:30:00.

Example

const date = new Temporal.PlainTime(14, 30);
Try it Yourself »

Create a PlainTime

You can create a PlainTime from a string.

Example

const time = Temporal.PlainTime.from("14:30");
Try it Yourself »

You can also create a PlainTime using numeric values.

Example

const time = new Temporal.PlainTime(14, 30);
Try it Yourself »

Note

The parameters are: hour, minute, second, millisecond, microsecond, nanosecond.


Get the Current Time

You can get the current local time using Temporal.Now.plainTimeISO().

Example

const now = Temporal.Now.plainTimeISO();
Try it Yourself »

Get Time Parts

You can read the different parts of a PlainTime value.

Example

const time = Temporal.PlainTime.from("14:30:15.123");
Try it Yourself »

Add and Subtract Time

Use add() and subtract() to do time math.

PlainTime is immutable, so the original value is not changed.

Example

const time = Temporal.PlainTime.from("14:30");

const later = time.add({ minutes: 45 });
const earlier = time.subtract({ hours: 2 });
Try it Yourself »

If the time passes midnight, it wraps around:

Example

const time = Temporal.PlainTime.from("23:30");

const result = time.add({ minutes: 90 });
Try it Yourself »

JavaScript Temporal since()

The since() method calculates the duration between two temporal dates.

Syntax

t1.since(t2, options)

Meaning:

At time t1, how much time has passed since time t2?

Example

const start = Temporal.PlainTime.from("09:00");
const end = Temporal.PlainTime.from("17:30");

const duration = end.since(start);
Try it Yourself »

Note

The since() method returns a Temporal.Duration Object representing the elapsed time.

The duration is positive if the "other" date is in the past.

The duration is negative if the "other" date is in the future.


Compare PlainTime Values

Use Temporal.PlainTime.compare() to compare times.

Example

// Create two PlainTime objects
const a = Temporal.PlainTime.from("08:30");
const b = Temporal.PlainTime.from("14:30");

// Compare the two objects
result = Temporal.PlainTime.compare(a, b));
Try it Yourself »

The result is:

  • -1 if the first time is earlier
  • 0 if they are equal
  • 1 if the first time is later

Note

Do not use =, <, or > when comparing temporal time.


Equal PlainTime Values

Use equals() to check if two times are the same.

Example

// Create two PlainTime objects
const a = Temporal.PlainTime.from("14:30");
const b = Temporal.PlainTime.from("14:30");

// Compare the two objects
result = a.equals(b);
Try it Yourself »

Calculate the Difference Between Two Times

Use until() or since() to calculate differences.

Examples

// Create two PlainTime objects
const start = Temporal.PlainTime.from("09:00");
const end = Temporal.PlainTime.from("17:30");

// Calculate the difference
const diff = start.until(end);
Try it Yourself »
// Create two PlainTime objects
const start = Temporal.PlainTime.from("09:00");
const end = Temporal.PlainTime.from("17:30");

// Calculate the difference
const diff = start.since(end);
Try it Yourself »

Note

The until() and since() methods return a Temporal.Duration.

The Temporal.PlainTime object has 6 properties of time information.

Example

const date = new Temporal.PlainTime(14, 30);
Try it Yourself »

When to Use PlainTime

  • Opening hours (for example: 09:00 to 17:00).

  • Alarm clock times.

  • Recurring daily schedules.

  • Time input fields (without date and time zone).

Note

If you need time zone support, use ZonedDateTime.


Summary

Temporal.PlainTime represents a time without date and time zone.

It is immutable, easy to compare, and useful for daily time values.

In the next chapter you will learn about PlainDateTime (a combo of PlainDate and PlainTime).


Temporal PlainTime Methods

ConstructingDescription
from()Returns a new PlainTime object from another object or a string
Arithmetic
add()Returns a new PlainTime with a duration added
subtract()Returns a new PlainTime with a duration subtracted
round()Returns a new PlainTime rounded to a given unit
Comparing
compare()Returns -1, 0, or 1 from comparing two times
equals()Returns true if two PlainTime objects are identical
since()Returns the difference since another time
until()Returns the difference until another time
Converting
with()Returns a new PlainTime with specified fields modified
Formatting
toString()Returns an RFC 9557 format string representation
toJSON()Returns an RFC 9557 format string for JSON serialization
toLocaleString()Returns a language-sensitive representation of the time
valueOf()Throws a TypeError (prevents temporals from being converted to primitives)

Temporal.PlainTime Properties

PropertyDescription
hourThe hour as an integer (0-23
microsecondThe microsecond as an integer (0-999)
millisecondThe millisecond as an integer (0-999)
minuteThe minute as an integer (0-59)
nanosecondThe nanosecond as an integer (0-999)
secondThe second as an integer (0-59)


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->