How to get unix timestamp?

I tried to get it, but failed

1 Like

Timespan methods aren’t exposed to Udon. If they were you could just subtract 1/1/1970 from the current date and then .TotalSeconds(). You can however do this immense bullshit instead

        System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);

        string timeSinceEpoch = (System.DateTime.UtcNow - epochStart).ToString();

        int days = int.Parse(timeSinceEpoch.Substring(0, 5));
        int hours = int.Parse(timeSinceEpoch.Substring(6, 2));
        int mins = int.Parse(timeSinceEpoch.Substring(9, 2));
        int secs = int.Parse(timeSinceEpoch.Substring(12, 2));

        days = (days * 24 * 60 * 60) + (hours * 60 * 60) + (mins * 60) + secs ;

        Debug.Log(days);

Thanks for the answer.

I tried it, but (System.DateTime.UtcNow - epochStart) return TimeSpan -_-

1 Like