LocalDateTimeUtil

This class provides utility methods for working with LocalDateTime objects. It includes methods for formatting, parsing, and extracting various date and time components.

Methods

formatted(date: LocalDateTime): String

  • Returns a default formatted string using the workflow's default formatting.

  • Parameters:

    • date (type: LocalDateTime) - The LocalDateTime object to format.

  • Returns:

    • A string representation of the formatted LocalDateTime.

var formattedDate = LocalDateTimeUtil.formatted(LocalDateTime.now());

format(date: LocalDateTime, format: String): String

  • Formats a LocalDateTime object using a custom date and time format pattern.

  • Parameters:

    • date (type: LocalDateTime) - The LocalDateTime object to format.

    • format (type: String) - The custom date and time format pattern. Follows the pattern format from SimpleDateFormat for Java.

  • Returns:

    • A string representation of the formatted LocalDateTime based on the specified format pattern.

var customFormattedDate = LocalDateTimeUtil.format(LocalDateTime.now(),
                                "yyyy-MM-dd HH:mm:ss");

parse(dateStr: String, format: String): LocalDateTime

  • Parses a date string using a custom format and returns a LocalDateTime object.

  • Parameters:

    • dateStr (type: String) - The date string to parse.

    • format (type: String) - The custom date and time format pattern used for parsing.

  • Returns:

    • A LocalDateTime object representing the parsed date and time.

var parsedDate = LocalDateTimeUtil.parse("2023-11-07 15:30:00", 
                                "yyyy-MM-dd HH:mm:ss");

getYear(date: LocalDateTime): Integer

  • Retrieves the year component of a LocalDateTime.

  • Parameters:

    • date (type: LocalDateTime) - The LocalDateTime object from which to extract the year.

  • Returns:

    • An integer representing the year component.

var year = LocalDateTimeUtil.getYear(LocalDateTime.now()); // returns 2023

getDayOfYear(date: LocalDateTime): Integer

  • Retrieves the day of the year component of a LocalDateTime.

  • Parameters:

    • date (type: LocalDateTime) - The LocalDateTime object from which to extract the day of the year.

  • Returns:

    • An integer representing the day of the year.

var dayOfYear = LocalDateTimeUtil.getDayOfYear(LocalDateTime.now()); 

getMonthName(date: LocalDateTime): String

  • Retrieves the name of the month for a LocalDateTime.

  • Parameters:

    • date (type: LocalDateTime) - The LocalDateTime object from which to extract the month name.

  • Returns:

    • A string representing the name of the month.

var monthName = LocalDateTimeUtil.getMonthName(LocalDateTime.now());
// returns "NOVEMBER"

getMonth(date: LocalDateTime): Integer

  • Retrieves the month component of a LocalDateTime.

  • Parameters:

    • date (type: LocalDateTime) - The LocalDateTime object from which to extract the month.

  • Returns:

    • An integer representing the month.

var month = LocalDateTimeUtil.getMonth(LocalDateTime.now());

getDayOfWeek(date: LocalDateTime): String

  • Retrieves the day of the week for a LocalDateTime.

  • Parameters:

    • date (type: LocalDateTime) - The LocalDateTime object from which to extract the day of the week.

  • Returns:

    • A string representing the day of the week.

var dayOfWeek = LocalDateTimeUtil.getDayOfWeek(LocalDateTime.now());
// returns "TUESDAY"

getDayOfMonth(date: LocalDateTime): Integer

  • Retrieves the day of the month component of a LocalDateTime.

  • Parameters:

    • date (type: LocalDateTime) - The LocalDateTime object from which to extract the day of the month.

  • Returns:

    • An integer representing the day of the month.

var dayOfMonth = LocalDateTimeUtil.getDayOfMonth(LocalDateTime.now());

getHour(date: LocalDateTime): Integer

  • Retrieves the hour component of a LocalDateTime.

  • Parameters:

    • date (type: LocalDateTime) - The LocalDateTime object from which to extract the hour.

  • Returns:

    • An integer representing the hour.

var hour = LocalDateTimeUtil.getHour(LocalDateTime.now());

getMinute(date: LocalDateTime): Integer

  • Retrieves the minute component of a LocalDateTime.

  • Parameters:

    • date (type: LocalDateTime) - The LocalDateTime object from which to extract the minute.

  • Returns:

    • An integer representing the minute.

var minute = LocalDateTimeUtil.getMinute(LocalDateTime.now());

getSecond(date: LocalDateTime): Integer

  • Retrieves the second component of a LocalDateTime.

  • Parameters:

    • date (type: LocalDateTime) - The LocalDateTime object from which to extract the second.

  • Returns:

    • An integer representing the second.

var second = LocalDateTimeUtil.getSecond(LocalDateTime.now());

getNano(date: LocalDateTime): Integer

  • Retrieves the nanosecond component of a LocalDateTime.

  • Parameters:

    • date (type: LocalDateTime) - The LocalDateTime object from which to extract the nanosecond.

  • Returns:

    • An integer representing the nanosecond.

var nano = LocalDateTimeUtil.getNano(LocalDateTime.now());

These methods provide various operations to work with LocalDateTime objects, including formatting, parsing, and extracting individual date and time components.