> For the complete documentation index, see [llms.txt](https://docs.b2winsuite.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.b2winsuite.com/5.2/scripting/static-classes/instantutil.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.b2winsuite.com/5.2/scripting/static-classes/instantutil.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
