{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-guides/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"type":"markdown"},"seo":{"title":"Timestamps","description":"Accelerate E&P application development and protect your innovation by consuming our Data and Domain APIs / Platform APIs.","lang":"en-US","meta":[{"name":"robots","content":"noindex"}],"llmstxt":{"hide":true,"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"timestamps","__idx":0},"children":["Timestamps"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AgoraTimeStamp"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["UTCDateTime"]}," are the two methods for consistent handling of timestamps.  The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AgoraTimeStamp"]}," is defined as the number of"," ","milliseconds since Jan. 1, 1970 (UTC) as a double .  It is expected that all times used between applications use ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AgoraTimeStamps"]}," to avoid"," ","miscommunication."]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AgoraTimeStamp"]}," is not affected by timezone.  When passing in a DateTime object to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AgoraTimeStamp"]}," it converts the time correctly to UTC time"," ","and delivers the correct corresponding timestamp. Additionally, the DateTime returned by ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["UTCDateTime"]}," is set to the UTC timezone."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For clarity, the code for ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AgoraTimeStamp"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["UTCDateTime"]}," is provided below:"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"_","__idx":1},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#tab/net"},"children":["NET"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"public static class Time\n{\n    public static double AgoraTimeStamp(DateTime? tm = null)\n    {\n        if (tm == null)\n            return (DateTime.UtcNow - DateTimeOffset.UnixEpoch).TotalMilliseconds;\n        return (tm.Value.ToUniversalTime() - DateTimeOffset.UnixEpoch).TotalMilliseconds;\n    }\n\n    public static DateTime UTCDateTime(double tm) => \n        new(DateTimeOffset.UnixEpoch.Ticks + (long)(tm * 10000), DateTimeKind.Utc);\n}\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"_-1","__idx":2},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#tab/python"},"children":["Python"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from datetime import datetime, timezone\n\ndef AgoraTimeStamp(tm=datetime.utcnow()) -> float:\n    dt_utc = datetime(tm.year, tm.month, tm.day,\n                      tm.hour, tm.minute, tm.second, tm. microsecond,\n                      tzinfo=timezone.utc)\n    delta = dt_utc.timestamp() - tm.timestamp()\n    return (tm.timestamp() + delta) * 1000\n\ndef UTCDateTime(tm: float) -> datetime:\n    dt = datetime.utcfromtimestamp(tm/1000).replace(tzinfo=timezone.utc)\n    return dt\n\nnow_time_stamp = AgoraTimeStamp()\nthen_time_stamp = AgoraTimeStamp() - 10000\n\nnow_date_time = UTCDateTime(now_time_stamp)\nthen_date_time = UTCDateTime(then_time_stamp)\n","lang":"python"},"children":[]}]},"headings":[{"value":"Timestamps","id":"timestamps","depth":2},{"value":"","id":"_","depth":1},{"value":"","id":"_-1","depth":1}],"frontmatter":{"seo":{"title":"Timestamps"}},"lastModified":"2025-12-30T09:56:50.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/solutions/agora/referencemanual/time","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}