# InstantUtil

The `InstantUtil` class provides a set of utility methods for working with `Instant` objects, allowing you to format, parse, and extract various date and time components.

### Methods

**formatted(dateInstant: Instant): String**

* Returns the default formatted string representation of an Instant object using the workflow's default formatting.

```typescript
var formattedInstant = InstantUtil.formatted(Instant.now());
```

**format(dateInstant: Instant, format: String, timeZone?: String): String**

* Formats an Instant object using the specified format pattern.

```typescript
var instant = Instant.now();
var format = "yyyy-MM-dd HH:mm:ss";
var formattedInstant = InstantUtil.format(instant, format);
return "Formatted Instant: " + formattedInstant;
```

**parse(dateStr: String, format: String, timeZone?: String): Instant**

* Parses a string representing a date and time into an Instant object using the specified format pattern.

```typescript
var instantStr = "2023-10-24T15:30:00Z";
var format = "yyyy-MM-dd'T'HH:mm:ss'Z'";
var parsedInstant = InstantUtil.parse(instantStr, format);
return "Parsed Instant: " + parsedInstant;
```

**getYear(dateInstant: Instant): Integer**

* Gets the year component from the provided Instant.

```typescript
var year = InstantUtil.getYear(Instant.now());
```

**getDayOfYear(dateInstant: Instant): Integer**

* Gets the day of the year from the provided Instant.

```typescript
var dayOfYear = InstantUtil.getDayOfYear(Instant.now());
```

**getMonthName(dateInstant: Instant): String**

* Gets the name of the month from the provided Instant.

```typescript
var monthName = InstantUtil.getMonthName(Instant.now());
```

**getMonth(dateInstant: Instant): Integer**

* Gets the month component from the provided Instant.

```typescript
var month = InstantUtil.getMonth(Instant.now());
```

**getDayOfWeek(dateInstant: Instant): String**

* Gets the name of the day of the week from the provided Instant.

```typescript
var dayOfWeek = InstantUtil.getDayOfWeek(Instant.now());
```

**getDayOfMonth(dateInstant: Instant): Integer**

* Gets the day of the month from the provided Instant.

```typescript
var dayOfMonth = InstantUtil.getDayOfMonth(Instant.now());
```

**getHour(dateInstant: Instant): Integer**

* Gets the hour component from the provided Instant.

```typescript
var hour = InstantUtil.getHour(Instant.now());
```

**getMinute(dateInstant: Instant): Integer**

* Gets the minute component from the provided Instant.

```typescript
var minute = InstantUtil.getMinute(Instant.now());
```

**getSecond(dateInstant: Instant): Integer**

* Gets the second component from the provided Instant.

```typescript
var second = InstantUtil.getSecond(Instant.now());
```

**getNano(dateInstant: Instant): Integer**

* Gets the nanoseconds within the second from the provided Instant.

```typescript
var nanoseconds = InstantUtil.getNano(Instant.now());
```

### Examples

**Example: Reformat a Date String**

**Description:** In this example, you have retrieved data with a date in a less user-friendly format, such as "2023-10-25T12:22:05.2247439Z." To improve data management and enhance readability, you will reformat the date information and introduce a new 'date' column.

Here we utilize several methods of InstantUtil: parse, getYear, getMonth, getDayOfMonth.

*Code:*

```java
// Reformat a Date String

// Parse the date string into an Instant
var instant = Instant.parse(datetime);

// Extract the year, month, and day components from the Instant
var year = InstantUtil.getYear(instant);
var month = InstantUtil.getMonth(instant);
var day = InstantUtil.getDayOfMonth(instant);

// Create a LocalDate object from the extracted components
var formattedDate = LocalDate.of(year, month, day);

// Now 'formattedDate' contains the date information in a structured, more readable format
```


---

# 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/5.4/scripting/utilities/date-and-time/instantutil.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.
