# LocalDateTime

## `LocalDateTime` Class

The `LocalDateTime` class represents a date and time without a time zone. It combines a `LocalDate` and a `LocalTime` to represent a specific date and time of day.

```typescript
var localdateTime = LocalDateTime.of(2023, 10, 24, 15, 30); 
// LDTIME 2023-10-24T15:30:00 
```

### Static Methods

#### `now(): LocalDateTime`

* Returns the current date and time.

```java
var currentDateTime = LocalDateTime.now();
```

#### `parse(text: String): LocalDateTime`

* Parses the input text to create a `LocalDateTime` instance.

```java
var parsedDateTime = LocalDateTime.parse("2023-10-24T15:30:45");
```

#### `of(year: Integer, month: Integer, dayOfMonth: Integer, hour: Integer, minute: Integer)`

* Creates a `LocalDateTime` instance with the specified year, month, day, hour, and minute values.

```java
var customDateTime = LocalDateTime.of(2023, 10, 24, 15, 30);
```

***

### Getter Methods

#### `getYear(): Int`

* Gets the year field.
* Returns the year as an `int` value.
* Example Usage:

  ```java
  var year = customDateTime.getYear();
  ```

#### `getMonthValue()`

* Gets the month-of-year field from 1 to 12.
* Returns the month as an `int` from 1 to 12.
* Example Usage:

  ```java
  var month = customDateTime.getMonthValue();
  ```

#### `getDayOfMonth()`

* Gets the day-of-month field.
* Returns the day-of-month as an `int` from 1 to 31.
* Example Usage:

  ```java
  var dayOfMonth = customDateTime.getDayOfMonth();
  ```

#### `getDayOfYear()`

* Gets the day-of-year field.
* Returns the day-of-year as an `int` from 1 to 365 (or 366 in a leap year).
* Example Usage:

  ```java
  var dayOfYear = customDateTime.getDayOfYear();
  ```

***

### Date Manipulation Methods

#### `minusYears(yearsToSubtract: Long)`

* Returns a new `LocalDateTime` with the specified number of years subtracted.
* Example Usage:

  ```java
  var newDateTime = customDateTime.minusYears(1);
  ```

#### `minusMonths(monthsToSubtract: Long)`

* Returns a new `LocalDateTime` with the specified number of months subtracted.
* Example Usage:

  ```java
  var newDateTime = customDateTime.minusMonths(2);
  ```

#### `minusWeeks(weeksToSubtract: Long)`

* Returns a new `LocalDateTime` with the specified number of weeks subtracted.
* Example Usage:

  ```java
  var newDateTime = customDateTime.minusWeeks(3);
  ```

#### `minusDays(daysToSubtract: Long)`

* Returns a new `LocalDateTime` with the specified number of days subtracted.
* Example Usage:

  <pre class="language-java"><code class="lang-java"><strong>var newDateTime = customDateTime.minusDays(10);
  </strong></code></pre>

#### `plusDays(daysToAdd: Long)`

* Returns a new `LocalDateTime` with the specified number of days added.
* Example Usage:

  ```java
  var newDateTime = customDateTime.plusDays(5);
  ```

#### `daysUntil(endDateTime: LocalDateTime)`

* Calculates the number of days until the specified end date and time.
* Example Usage:

  ```java
  var daysUntil = customDateTime.daysUntil(endDateTime);
  ```

#### `monthsUntil(endDateTime: LocalDateTime)`

* Calculates the number of months until the specified end date and time.
* Example Usage:

  ```java
  var monthsUntil = customDateTime.monthsUntil(endDateTime);
  ```

***

### Comparison Methods

#### `isBefore(other: LocalDateTime)`

* Checks if the current date and time is before the specified date and time.
* Returns `true` if the current date and time is before `other`, `false` otherwise.
* Example Usage:

  ```java
  var isBefore = customDateTime.isBefore(parsedDateTime);
  ```

#### `isAfter(other: LocalDateTime)`

* Checks if the current date and time is after the specified date and time.
* Returns `true` if the current date and time is after `other`, `false` otherwise.
* Example Usage:

  ```java
  var isAfter = customDateTime.isAfter(parsedDateTime);
  ```

***

### Date-Time Separation Methods

#### `toLocalDate()`

* Gets the `LocalDate` part of this date-time.
* Returns a `LocalDate` with the same year, month, and day as this date-time.
* Example Usage:

  ```java
  var datePart = customDateTime.toLocalDate();
  ```

#### `toLocalTime()`

* Gets the `LocalTime` part of this date-time.
* Returns a `LocalTime` with the same hour, minute, second, and nanosecond as this date-time.
* Example Usage:

  ```java
  var timePart = customDateTime.toLocalTime();
  ```


---

# 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/types-and-objects/objects/localdatetime.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.
