For the complete documentation index, see llms.txt. This page is also available as Markdown.

Environment.getServerTime

Functional API getServerTimeYou can use the same function with this as well.

Feature description

Gets the current time of the Toss app server as a Unix timestamp (milliseconds). Since it is based on the server rather than the device time, it helps reduce cheating caused by client-side time manipulation.

Toss app Android/iOS 5.245.0 You can use it on version and above. Before calling, Environment.getServerTime.isSupported()you can check whether it is supported. If you call it on an unsupported version, UNSUPPORTED_APP_VERSION an error occurs.

Type

Environment.getServerTime(): Promise<number>;

Params

None

Response

Returns the server time as a Unix timestamp (milliseconds). For example 1705123456789.

Error

The error code is the error.code value.

Code
Description

UNSUPPORTED_APP_VERSION

If the running version of the Toss app doesn't support this feature, it occurs immediately upon call. Environment.getServerTime.isSupported()Check in advance with error.messageand, if it occurs, show the user the (update guidance message).

Example code

import { Environment } from "@apps-in-toss/web-framework";

try {
  const serverTime = await Environment.getServerTime();
  console.log(serverTime);
} catch (error) {
  console.error(error);
}

Was this helpful?