formatTimeByUnicodePattern

fun formatTimeByUnicodePattern(unicodePattern: String, time: SimpleTime, language: NepaliDatePickerLang = NepaliDatePickerLang.ENGLISH): String(source)

Formats a time based on the specified Unicode pattern and language preferences.

Return

A string representing the formatted time according to the provided Unicode pattern and language preferences.

The function supports the following placeholders in the unicodePattern:

  • HH: Hour in 24-hour format (00–23) (e.g., "08" or "०८")

  • H: Hour in 24-hour format, no padding (e.g., "8" or "८")

  • hh: Hour in 12-hour format (01–12) (e.g., "01" or "०१")

  • h: Hour in 12-hour format, no padding (e.g., "1" or "१")

  • mm: Minutes, two-digit (e.g., "05" or "०५")

  • m: Minutes, no padding (e.g., "5" or "५")

  • ss: Seconds, two-digit (e.g., "09" or "०९")

  • s: Seconds, no padding (e.g., "9" or "९")

  • SSSS: Four-digit nanosecond precision (e.g., "1234" or "१२३४")

  • SSS: Millisecond precision (e.g., "123" or "१२३")

  • SS: Two-digit fractional seconds (e.g., "12" or "१२")

  • S: One-digit fractional second (e.g., "1" or "१")

  • a: Lowercase AM/PM or localized period (e.g., "am" or "बिहान")

  • A: Uppercase AM/PM or localized period (e.g., "AM" or "साँझ")

Example usage:

val time = SimpleTime(hour = 15, minute = 30, second = 45, nanosecond = 123)
val formattedTime = formatTimeByUnicodePattern(
calendar,
time,
"hh:mm:ss.SSS A"
)
// formattedTime: "03:30:45.123 PM"

Parameters

time

A SimpleTime that holds the time details (hour, minute, second, nanosecond).

unicodePattern

A string specifying the pattern to use for formatting the date and time. The pattern supports various placeholders like "HH", "hh", "mm", "ss", "SSS", "a", etc.

language

The NepaliDatePickerLang specifying the language for formatting the date and time.