Instant

Instant Class

The Instant class is a fundamental component of B2Win Suite Scripting, allowing you to work with instants in time. This class provides methods for creating and manipulating time-related data.

Static Methods

  • Instant.now(): Instant

Description: Returns an instance representing the current instant.

Example:

var currentInstant = Instant.now();

  • Instant.parse(text: String)

Description: Parses a string and returns an instance of Instant.

Example:

var parsedInstant = Instant.parse("2023-10-20T12:00:00Z");

Comparison Methods

  • isBefore(otherInstant: Instant)

Description: Compares this Instant with another Instant and returns true if it is before the other instant or false otherwise.

Example:

var instantA = Instant.parse("2023-10-20T08:00:00Z"); // parse Instant A
var instantB = Instant.parse("2023-10-20T09:00:00Z"); // parse Instant B

var isBefore = instantA.isBefore(instantB);

if (isBefore) {
    // Do something when instantA is before instantB
    return "instantA is before instantB";
} else {
    // Do something when instantA is not before instantB
    return "instantA is not before instantB";
}

  • isAfter(otherInstant: Instant)

Description: Compares this Instant with another Instant and returns true if it is after the other instant or false otherwise.

Example:

var isAfter = instantA.isAfter(instantB);

if (isAfter) {
    // Do something when instantA is after instantB
    return "instantA is after instantB";
} else {
    // Do something when instantA is not after instantB
    return "instantA is not after instantB";
}

Conversion Methods

  • toEpochMilli()

Description: Converts this Instant to the number of milliseconds since the epoch (00:00:00 UTC on 1 January 1970) and returns the value in type Long.

Example:

var myInstant = Instant.parse("2023-10-20T08:00:00Z");
var epochMillis = myInstant.toEpochMilli();

  • toString()

Description: Converts this Instant to a string representation and returns it.

Example:

var myInstant = Instant.parse("2023-10-20T08:00:00Z");
var instantString = myInstant.toString();

Last updated