# LocalDateTimeUtil

This class provides utility methods for working with [LocalDateTime ](/scripting/types-and-objects/objects/localdatetime.md)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.

```typescript
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.

```typescript
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.

```typescript
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.

```typescript
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.

```typescript
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.

```typescript
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.

```typescript
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.

```typescript
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.

```typescript
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.

```typescript
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.

```typescript
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.

```typescript
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.

```typescript
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.b2winsuite.com/scripting/utilities/date-and-time/localdatetimeutil.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
