JavaScript Intl RelativeTimeFormat() Constructor Last Updated : 12 Apr, 2023 Comments Improve Suggest changes Like Article Like Report JavaScript Intl RelativeTimeFormat() Constructor is used for creating Intl.RelativeTimeFormat object. This constructor is created using the new keyword. If we create the constructor without the new keyword it will give a TypeError. Syntax: new Intl.RelativeTimeFormat(loc, opt) Parameters: It has two parameters both are optional. loc: It is a String or an array of Strings that contains the general form and interpretation of argumentsopt: It is an object which contains properties like localeMatcher and style and numeric. Return Value: An Intl.RelativeFormat object. Below examples illustrate the JavaScript Intl RelativeTimeFormat() Constructor: Example 1: This example creates a basic RelativeTimeFormat Object and uses it to format the time. JavaScript const timeFormat = new Intl.RelativeTimeFormat("en",{ localeMatcher: "lookup", numeric: "always", style: "short", }); console.log(timeFormat.format(-2,"year")); console.log(timeFormat.format(-3,"week")); Output: 2 yr. ago VM162:8 3 wk. ago Example 2: This example uses RelativeTimeFormat Object with auto property JavaScript const timeFormat = new Intl.RelativeTimeFormat("en",{ localeMatcher: "lookup", numeric: "auto", style: "long", }); console.log(timeFormat.format(2,"day")); console.log(timeFormat.format(-3,"day")); Output: in 2 days 3 days ago Supported Browsers: ChromeEdgeFirefoxOperaSafari We have a complete list of JavaScript Intl methods to check please go through, the JavaScript Intl Reference article Comment More infoAdvertise with us Next Article JavaScript Intl RelativeTimeFormat() Constructor S shobhit_sharma Follow Improve Article Tags : JavaScript Web Technologies Similar Reads JavaScript Intl DateTimeFormat() Constructor JavaScript Intl.DateTimeFormat Constructor is used for creating Intl.DateTimeFormat objects. This constructor can be called with or without the new keyword Syntax: Intl.DateTimeFormat(loc, opt) new Intl.DateTimeFormat(loc, opt) Parameter: This constructor has two methods and both are optional. loc: 2 min read DateFormat getTimeInstance() Method in Java with Examples DateFormat class of java.text package is an abstract class that is used to format and parse dates for any locale. It allows us to format date to text and parse text to date. DateFormat class provides many functionalities to obtain, format, parse default date/time. Note: DateFormat class extends Form 2 min read java.time.LocalTime Class in Java Java is the most popular programming language and widely used programming language. Java is used in all kinds of applications like mobile applications, desktop applications, web applications. As in Java, java.time.LocalTime class represents time, which is viewed as hour-minute-second. This class is 5 min read LocalTime format() method in Java with Examples The format() method of a LocalTime class is used to format this time using the specified formatter passed as a parameter. This method formats this time based on passed formatter to a string. Syntax: public String format(DateTimeFormatter formatter) Parameters: This method accepts a single parameter 2 min read DateFormat Class in Java The java.text.DateFormat is an abstract class that is used to format and parse dates for any locale. It allows us to format date to text and parse text to date. DateFormat class provides many functionalities to obtain, format, parse default date/time. DateFormat class extends Format class that means 4 min read LocalDateTime withNano() method in Java with Examples withNano() method of LocalDateTime class in Java is used to get a copy of this LocalDateTime with the nano-seconds changed to the nano-seconds passed as the parameter to this method. The remaining values of this LocalDateTime remain the same. Syntax: public LocalDateTime withNano(int nanoSeconds) Pa 3 min read LocalDateTime format() method in Java The format() method of LocalDateTime class in Java formats this date-time using the specified formatter. Syntax: public String format(DateTimeFormatter formatter) Parameter: This method accepts a parameter formatter which specifies the formatter to use, not null. Returns: The function returns the fo 2 min read DateFormat getDateTimeInstance() Method in Java with Examples DateFormat class of java.text package is an abstract class that is used to format and parse dates for any locale. It allows us to format date to text and parse text to date. DateFormat class provides many functionalities to obtain, format, parse default date/time. Note: DateFormat class extends Form 2 min read DateFormat format(Date obj) method in Java The format() method of DateFormat class in Java is used to format a given Date object into a string representing Date/Time.Syntax: String format(Date date) Parameters: This method accepts a single parameter date which is a Date object. Return Value: This method returns a String which is the formatte 2 min read ChronoLocalDateTime format() method in Java with Examples The format() method of ChronoLocalDateTime interface in Java formats this date-time using the specified formatter. Syntax: default String format(DateTimeFormatter formatter) Parameter: This method accepts a parameter formatter which specifies the DateTimeFormatter to use, not null. Returns: The func 2 min read Like