Time in UnrealScript

class TimeExample extends Object;

var DateTime Now;
var DateTime Then;
var TimeSpan Diff;

function Init()
{
    // We'll start by getting the current time.
    Now = class'WorldInfo'.static.GetWorldInfo().TimeSeconds;
    `log("Current time:" @ Now);

    // You can build a DateTime struct by providing the
    // year, month, day, etc.
    Then = class'DateTime'.static.CreateDateTime(2009, 11, 17, 20, 34, 58, 651);
    `log("Then time:" @ Then);

    // You can extract the various components of the time
    // value as expected.
    `log("Year:" @ Then.Year);
    `log("Month:" @ Then.Month);
    `log("Day:" @ Then.Day);
    `log("Hour:" @ Then.Hour);
    `log("Minute:" @ Then.Minute);
    `log("Second:" @ Then.Second);
    `log("Millisecond:" @ Then.Millisecond);

    // The day of the week is also available.
    `log("Day of Week:" @ Then.DayOfWeek);

    // These methods compare two times, testing if the
    // first occurs before, after, or at the same time
    // as the second, respectively.
    `log("Then is before Now:" @ (Then < Now));
    `log("Then is after Now:" @ (Then > Now));
    `log("Then is equal to Now:" @ (Then == Now));

    // We can calculate the difference between two DateTimes.
    Diff = Now - Then;
    `log("Time difference:" @ Diff);

    // We can compute the length of the duration in
    // various units.
    `log("Hours:" @ Diff.GetHours());
    `log("Minutes:" @ Diff.GetMinutes());
    `log("Seconds:" @ Diff.GetSeconds());
    `log("Milliseconds:" @ Diff.GetMilliseconds());

    // You can use addition to advance a time by a given
    // duration, or subtraction to move backwards.
    `log("Then plus diff:" @ (Then + Diff));
    `log("Then minus diff:" @ (Then - Diff));
}

DefaultProperties
{
}

This UnrealScript example demonstrates time and duration operations similar to the original example. Here are some key points about the translation:

  1. UnrealScript uses DateTime for representing points in time and TimeSpan for durations.

  2. The WorldInfo.TimeSeconds is used to get the current time.

  3. DateTime.CreateDateTime() is used to create a specific date and time.

  4. UnrealScript doesn’t have built-in UTC support, so time zone information is omitted.

  5. Comparison between DateTimes is done using standard comparison operators (<, >, ==).

  6. The difference between two DateTimes results in a TimeSpan.

  7. TimeSpan methods are used to get duration in various units.

  8. Addition and subtraction operators are used with DateTime and TimeSpan for time calculations.

  9. UnrealScript uses backtick-prefixed log for console output instead of a print function.

To run this code, you would typically place it in a script file within your UnrealScript project and either call the Init() function from elsewhere in your game code or set up the class to be automatically instantiated by the engine.

Note that UnrealScript’s DateTime and TimeSpan functionalities might not be as extensive as Go’s time package, but this example covers the main concepts of time manipulation in UnrealScript.