private static string UID = "XYZ"; // Change XYZ to the UID of your Real-Time Clock Bricklet

    #endregion Fields

    #region Methods

    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletRealTimeClock rtc = new BrickletRealTimeClock(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT); // Connect to brickd
        // Don't use device before ipcon is connected

        // Get current date and time
        int year; byte month, day, hour, minute, second, centisecond, weekday;
        rtc.GetDateTime(out year, out month, out day, out hour, out minute, out second,
                        out centisecond, out weekday);

        Console.WriteLine("Year: " + year);
        Console.WriteLine("Month: " + month);
        Console.WriteLine("Day: " + day);
        Console.WriteLine("Hour: " + hour);
        Console.WriteLine("Minute: " + minute);
        Console.WriteLine("Second: " + second);
        Console.WriteLine("Centisecond: " + centisecond);
        Console.WriteLine("Weekday: " + weekday);

        // Get current timestamp (unit is ms)
        long timestamp = rtc.GetTimestamp();
        Console.WriteLine("Timestamp: " + timestamp + " ms");

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
    private static string UID = "XYZ"; // Change XYZ to the UID of your Real-Time Clock Bricklet

    #endregion Fields

    #region Methods

    // Callback function for date and time callback
    static void DateTimeCB(BrickletRealTimeClock sender, int year, byte month, byte day,
	                       byte hour, byte minute, byte second, byte centisecond,
	                       byte weekday, long timestamp)
    {
        Console.WriteLine("Year: " + year);
        Console.WriteLine("Month: " + month);
        Console.WriteLine("Day: " + day);
        Console.WriteLine("Hour: " + hour);
        Console.WriteLine("Minute: " + minute);
        Console.WriteLine("Second: " + second);
        Console.WriteLine("Centisecond: " + centisecond);
        Console.WriteLine("Weekday: " + weekday);
        Console.WriteLine("Timestamp: " + timestamp);
        Console.WriteLine("");
    }
    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletRealTimeClock rtc = new BrickletRealTimeClock(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT); // Connect to brickd
        // Don't use device before ipcon is connected

        // Register date and time callback to function DateTimeCB
        rtc.DateTime += DateTimeCB;

        // Set period for date and time callback to 5s (5000ms)
        // Note: The date and time callback is only called every 5 seconds
        //       if the date and time has changed since the last call!
        rtc.SetDateTimeCallbackPeriod(5000);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }