format

fun Calendar.format(pattern: String): String

Formats a Calendar into a date-time String.

Since

1.1.1

Return

The formatted date-time string.

See also

Throws

IllegalArgumentException

if the given pattern is invalid


fun Date.format(pattern: String): String

Formats a Date into a date-time String.

Example:

1659814200000.toDate().format("MM/dd/yyyy") // 08/07/2022

Since

1.1.1

Return

The formatted date-time string.

See also

Throws

IllegalArgumentException

if the given pattern is invalid


fun Instant.format(pattern: String): String

Formats a Instant into a date-time String.

Example:

1659814200000.toInstant().format("MM/dd/yyyy") // 08/07/2022

Since

1.1.1

Return

The formatted date-time string.

See also

Throws

IllegalArgumentException

if the given pattern is invalid


fun LocalDate.format(pattern: String): String

Formats a LocalDate into a date-time String.

Example:

1659814200000.toLocalDate().format("MM/dd/yyyy") // 08/07/2022

Since

1.1.1

Return

The formatted date-time string.

See also

Throws

IllegalArgumentException

if the given pattern is invalid


fun LocalDateTime.format(pattern: String): String

Formats a LocalDateTime into a date-time String.

Example:

1659814205950.toLocalDateTime().format("MM/dd/yyyy") // 08/07/2022

Since

1.1.1

Return

The formatted date-time string.

See also

Throws

IllegalArgumentException

if the given pattern is invalid


fun LocalTime.format(pattern: String): String

Formats a LocalTime into a date-time String.

Example:

val time = LocalTime(11, 10, 0)
time.toLocalDate().format("HH") // 11

Since

1.1.1

Return

The formatted date-time string.

See also

Throws

IllegalArgumentException

if the given pattern is invalid