Skip to main content

Get Server Time

This API retrieves the current server time.

URL Confirmation

This API uses the api.playnanoo.com domain.

API Information

  • URL: https://api.playnanoo.com/server_time/call
  • Method: POST
  • Authentication Required: Yes
DeviceInfo Inheritance

The Req class of this API inherits from DeviceInfo. All properties of DeviceInfo are automatically included.

Request Parameters

ParameterTypeRequiredDescription
udidstringRequiredDevice ID (for per-minute request limiting)

Response Data

Res Class

FieldTypeDescription
codeintResponse code
messagestringResponse message
valueServerTimeValueServer time information

ServerTimeValue Class

FieldTypeDescription
timezonestringTimezone
timestampintUnix timestamp
ISO_8601_datestringISO 8601 format date
datestringDate (YYYY-MM-DD)
yearstringYear
monthstringMonth
daystringDay
hourstringHour
minutestringMinute
secondstringSecond

Unity C# Implementation

BaseResponse Class

Base class for all API responses.

public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}

Field descriptions:

  • ErrorCode: Error code
  • Message: Error message
  • WithdrawalKey: Key required for recovery if account is in withdrawal grace period (only provided for accounts in withdrawal grace period)
  • BlockKey: Key provided if account is blocked (only provided for blocked accounts)

Server Time Retrieval Class

using System;
using System.Collections;
using UnityEngine.Networking;

public class ServerTime
{
static string path = "https://api.playnanoo.com/server_time/call";

[Serializable]
public class Req : DeviceInfo
{
public string udid;

public IEnumerator Send(Action<Res> onSuccess, Action<BaseResponse> onError)
{
udid = device_id; // Added for per-minute rate limiting by device/app

yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPOST,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}

[Serializable]
public class Res : BaseResponse
{
public int code;
public string message;
public ServerTimeValue value;
}

[Serializable]
public class ServerTimeValue
{
public string timezone;
public int timestamp;
public string ISO_8601_date;
public string date;
public string year;
public string month;
public string day;
public string hour;
public string minute;
public string second;
}
}

Usage Examples

Basic Usage

using PlayNANOO;

public class PlayNANOOExample : MonoBehaviour
{
void GetServerTime()
{
ServerTime.Req req = new ServerTime.Req();

StartCoroutine(req.Send(
onSuccess: res =>
{
Debug.Log($"Response Code: {res.code}");
Debug.Log($"Response Message: {res.message}");
Debug.Log($"Server Timestamp: {res.value.timestamp}");
Debug.Log($"Server Date: {res.value.date}");
Debug.Log($"Server Time: {res.value.hour}:{res.value.minute}:{res.value.second}");
Debug.Log($"ISO 8601: {res.value.ISO_8601_date}");
},
onError: (error) =>
{
Debug.LogError($"Failed to retrieve server time: [{error.ErrorCode}] [{error.Message}]");
}
));
}
}

Client-Server Time Synchronization

using PlayNANOO;
using UnityEngine;

public class TimeSync : MonoBehaviour
{
private int serverTimestamp;
private float localTimeAtSync;
private bool isSynced = false;

void Start()
{
SyncWithServer();
}

public void SyncWithServer()
{
ServerTime.Req req = new ServerTime.Req();

StartCoroutine(req.Send(
onSuccess: res =>
{
serverTimestamp = res.value.timestamp;
localTimeAtSync = Time.realtimeSinceStartup;
isSynced = true;
Debug.Log($"Time sync complete: {res.value.date} {res.value.hour}:{res.value.minute}:{res.value.second}");
},
onError: (error) =>
{
Debug.LogError($"Time sync failed: {error.Message}");
}
));
}

public int GetCurrentServerTimestamp()
{
if (!isSynced)
{
Debug.LogWarning("Server time is not synchronized.");
return 0;
}

float elapsedTime = Time.realtimeSinceStartup - localTimeAtSync;
return serverTimestamp + (int)elapsedTime;
}

public DateTime GetCurrentServerDateTime()
{
int currentTimestamp = GetCurrentServerTimestamp();
return DateTimeOffset.FromUnixTimeSeconds(currentTimestamp).DateTime;
}
}

Event Time Check

using PlayNANOO;
using UnityEngine;
using System;

public class EventTimeChecker : MonoBehaviour
{
private ServerTime.ServerTimeValue serverTime;

void CheckEventTime()
{
ServerTime.Req req = new ServerTime.Req();

StartCoroutine(req.Send(
onSuccess: res =>
{
serverTime = res.value;

// Compare with event start/end times
int eventStartHour = 10; // 10 AM
int eventEndHour = 22; // 10 PM

int currentHour = int.Parse(serverTime.hour);

if (currentHour >= eventStartHour && currentHour < eventEndHour)
{
Debug.Log("Event is in progress!");
EnableEvent();
}
else
{
Debug.Log("Event is not active.");
DisableEvent();
}
},
onError: (error) =>
{
Debug.LogError($"Failed to retrieve server time: {error.Message}");
}
));
}

void EnableEvent()
{
// Event activation logic
}

void DisableEvent()
{
// Event deactivation logic
}
}
Using Server Time

Server time can be used to check game event start/end times, validate timestamps, etc. To prevent client time manipulation, important time checks should always be based on server time.

Per-Minute Request Limit

The number of requests per minute may be limited by device and app. Avoid excessive calls and query server time only when necessary.