> For the complete documentation index, see [llms.txt](https://lionstudios.gitbook.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lionstudios.gitbook.io/readme/migration-guide/server-time.md).

# Server Time

This guide outlines the steps to migrate from the deprecated `LionGameInterfaces.Time.GetServerTime` or `NakamaConnection.GetServerTime` to the new `GlobalConfigHandler` approach for retrieving server time.

### Overview <a href="#user-content-overview" id="user-content-overview"></a>

The previous methods for fetching server time via `LionGameInterfaces` or direct `NakamaConnection` calls have been replaced. The new standard uses `GlobalConfigHandler` located in the `WhoAmI` service to fetch the time configuration directly.

### ❌ Old Way (Deprecated) <a href="#user-content--old-way-deprecated" id="user-content--old-way-deprecated"></a>

Previously, you might have accessed server time using `LionGameInterfaces` or a custom interface implementation:

```
var time = await LionGameInterfaces.Time.GetCurrentTimeUTC();
```

### ✅ New Way (Recommended) <a href="#user-content--new-way-recommended" id="user-content--new-way-recommended"></a>

You should now retrieve the server time string from `GlobalConfigHandler`, parse it as a Unix timestamp (milliseconds), and convert it to a `DateTime` object.

#### Implementation Steps <a href="#user-content-implementation-steps" id="user-content-implementation-steps"></a>

1. **Fetch the string** using `GlobalConfigHandler.GetInfo<string>("serverTime")`.
2. **Parse** the string into a `long` (Unix timestamp in milliseconds).
3. **Convert** the timestamp to a UTC `DateTime`.

#### Code Example <a href="#user-content-code-example" id="user-content-code-example"></a>

{% code overflow="wrap" lineNumbers="true" %}

```csharp
using LionStudios.Suite.Core; 
// Ensure you have this namespace
using System;
using System.Threading.Tasks;

public async Task<DateTime> GetCurrentServerTime()
{    
    // 1. Get the server time string from Global Config    
    string serverTimeStr = await GlobalConfigHandler.GetInfo<string>("serverTime");    
    // 2. Parse string to long (Unix Milliseconds)    
    if (long.TryParse(serverTimeStr, out long unixMs))    
    {        
        // 3. Convert to DateTime UTC        
        DateTime utcTime = DateTimeOffset.FromUnixTimeMilliseconds(unixMs).UtcDateTime;        
        return utcTime;    
    }    
    // Fallback if parsing fails (e.g., return local UTC or throw)    
    return DateTime.UtcNow;
}
```

{% endcode %}

#### One-Liner (If you are confident in the data) <a href="#user-content-one-liner-if-you-are-confident-in-the-data" id="user-content-one-liner-if-you-are-confident-in-the-data"></a>

```csharp
DateTime utcTime = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(
await GlobalConfigHandler.GetInfo<string>("serverTime"))).UtcDateTime;
```

### Summary of Changes <a href="#user-content-summary-of-changes" id="user-content-summary-of-changes"></a>

| Feature          | Old Approach                                   | New Approach                    |
| ---------------- | ---------------------------------------------- | ------------------------------- |
| **Access Point** | `LionGameInterfaces.Time` / `NakamaConnection` | `GlobalConfigHandler`           |
| **Method**       | `GetCurrentTimeUTC()` / custom WebRequest      | `GetInfo<string>("serverTime")` |
| **Return Type**  | `DateTime` (often hidden implementation)       | `string` (Unix Timestamp MS)    |
| **Namespace**    | `LionStudios.Suite.Core`                       | `LionStudios.Suite.Core`        |

### Troubleshooting <a href="#user-content-troubleshooting" id="user-content-troubleshooting"></a>

* **Missing Namespace:** Ensure you are using `LionStudios.Suite.Core`.
* **Parsing Errors:** The `serverTime` key returns a string representation of a `long`. Always use `long.Parse` or `long.TryParse`.
* **Async/Await:** `GlobalConfigHandler.GetInfo` is asynchronous. Ensure your calling method is `async` and valid for use (e.g., not in a constructor).


---

# 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://lionstudios.gitbook.io/readme/migration-guide/server-time.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.
