Get the exact time for a remote server

check time on remote computer
get network time

In C#, how do I query a remote server for its current time?

Similar functionality to

net time \\servername

but returning a datestamp that includes seconds.


Windows Time Service implements NTP. Here is a C# implementation of an NTP client. A Windows GUI using it can be found at Simple Network Time Protocol Client. It's by Valer Bocan.

How can I display the current date and time on a remote computer by using Use Windows PowerShell remoting, and the Invoke-Command cmdlet to run Get-​Date. local time zone, how can we display the time in the remote server's Sitesofficial rulesOliver Lipkauoperating systemOracleother Directory  Working like a charm. And it doesn't need remote server to have Windows Time Service running (@Reed Copsey answer) or port 13 open (@Zanoni answer) or access to the filesystem (@bluish answer). This approach works with Windows 2000 or higher - perfect.. – bairog May 26 '14 at 11:10

You can use the NetRemoteTOD function.

An example from

// The pointer.
IntPtr pintBuffer = IntPtr.Zero;

// Get the time of day.
int pintError = NetRemoteTOD(@"\\sony_laptop", ref pintBuffer);

// Get the structure.
Marshal.PtrToStructure(pintBuffer, typeof(TIME_OF_DAY_INFO));

// Free the buffer.

"servername" is replaced with the name of the actual server that you want to get the date/time from: Hide Copy Code. Dim dRemoteDate As Date dRemoteDate  First we need to deal with getting the timezone of the remote server, and if we take a trip down memory lane we can find the answer to that we just need to use the invoke command we tried earlier and this properly returns the right information instead of being automatically translated into our culture.

You can try getting the daytime on port 13:

System.Net.Sockets.TcpClient t = new System.Net.Sockets.TcpClient ("yourmachineHOST", 13);
System.IO.StreamReader rd = new System.IO.StreamReader (t.GetStream ()); 
Console.WriteLine (rd.ReadToEnd ());

Do you have problems with time synchronization in your Active the system time of your servers, workstations or domain-controllers? provide you with an advanced PowerShell function that will remotely retrieve the system… Here’s a simply Powershell script to query the time on remote machines via WMI. You could use Invoke-Command with Get-Date, but that takes too long compared to just using WMI.

Below is a more complete implementation.

Usage: DateTime? now = RemoteTOD.GetNow(@"\\ServerName");

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

public static class RemoteTOD {

    // Important: CharSet must be Unicode otherwise error 2184 is returned
    [DllImport("netapi32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
    private static extern int NetRemoteTOD(String UncServerName, ref IntPtr BufferPtr);

    private static extern void NetApiBufferFree(IntPtr bufptr);

    public static DateTime? GetNow(String serverName, bool throwException = false) {
        IntPtr ptrBuffer = IntPtr.Zero;
        int result = NetRemoteTOD(serverName, ref ptrBuffer);
        if (result != 0) {
            if (throwException)
                throw new Win32Exception(Marshal.GetLastWin32Error());
            return null;

        TIME_OF_DAY_INFO tod = (TIME_OF_DAY_INFO) Marshal.PtrToStructure(ptrBuffer, typeof(TIME_OF_DAY_INFO));
        NetApiBufferFree(ptrBuffer); // must be freed using NetApiBufferFree according to the documentation

        //DateTime d0 = new DateTime(1970,1,1);
        //d0 = d0.AddSeconds(tod.elapsedt);
        DateTime nowUtc = new DateTime(tod.year, tod.month,, tod.hour, tod.minute, tod.second, 10 * tod.hunds);
        DateTime now = nowUtc.ToLocalTime();
        return now;

public struct TIME_OF_DAY_INFO {

    ///<summary>The number of seconds since 00:00:00, January 1, 1970, GMT.</summary>
    public int elapsedt;

    ///<summary>The number of milliseconds from an arbitrary starting point (system reset). Typically, this member is read twice,
    ///once when the process begins and again at the end. To determine the elapsed time between the process's start and finish,
    ///you can subtract the first value from the second.</summary>
    public int msecs;

    ///<summary>The current hour. Valid values are 0 through 23.</summary>
    public int hour;

    ///<summary>The current minute. Valid values are 0 through 59.</summary>
    public int minute;

    ///<summary>The current second. Valid values are 0 through 59.</summary>
    public int second;

    ///<summary>The current hundredth second (0.01 second). Valid values are 0 through 99.</summary>
    public int hunds;

    ///<summary>The time zone of the server. This value is calculated, in minutes, from Greenwich Mean Time (GMT). For time zones
    ///west of Greenwich, the value is positive; for time zones east of Greenwich, the value is negative. A value of –1 indicates
    ///that the time zone is undefined.</summary>
    public int timezone;

    ///<summary>The time interval for each tick of the clock. Each integral integer represents one ten-thousandth second (0.0001 second).</summary>
    public int tinterval;

    ///<summary>The day of the month. Valid values are 1 through 31.</summary>
    public int day;

    ///<summary>The month of the year. Valid values are 1 through 12.</summary>
    public int month;

    ///<summary>The year.</summary>
    public int year;

    ///<summary>The day of the week. Valid values are 0 through 6, where 0 is Sunday, 1 is Monday, and so on.</summary>
    public int weekday;

Results on Server Performance (1) Sensor data update time (PUT) vs. connected update them in the database and receive back a response from the server. with the exact time that the first PUT request is sent and ends when the server  It gives you remote access to the server cmd line. From there you could sync against a server with the correct time. Or enable the telnet server on the remote machine and do it that way.

Using the C# NTP client in Reed Copsey (& David Laing) answer, you can get a time "now" stamp (in ms) from a domain controller / NTP server using:

InternetTime.SNTPClient sntp = new InternetTime.SNTPClient("");
sntp.Connect(false); // true to update local client clock
DateTime dt = sntp.DestinationTimestamp.AddMilliseconds(sntp.LocalClockOffset);
string timeStampNow = dt.ToString("dd/MM/yyyy HH:mm:ss.fff");

Dang a quick check with Get-Help will reveal though that Get-Date doesn't support an option to execute it against a remote computer. So that won  So today we will see how to get the last boot time of remote computers using Powershell. Let me tell you how I got the idea of writing this article, when I was working on an issue and I realised that the computer was not responding through the Remote Desktop and I was trying to restart the machine remotely, but was not sure if the commands were

I have checked the server and the time is correct. Checking the event logs it is saying The RPC server is unavailable I'm not sure if this is related. Additional note:  If you plan on deploying your website on someone else's server, then you may not want to hardcode the server time, as the server may move to an unknown timezone. Then it may be best to set the default time zone in the php.ini file.

YOU HAVE BEEN WARNED. TIME The NET TIME command allows you to view the time on a remote server or synchronise the time on the local server with the  The Get-RemoteAccessConnectionStatisticsSummary cmdlet displays the summary statistics of real-time, currently active DirectAccess (DA) and VPN connections and the summary statistics of DA and VPN historical connections for a specified duration time. The statistics summary for active and historical connections starting or ending on a Remote Access server are stored in the inbox accounting store on that server.

The local routers that receive time from an NTP peer run in what is called NTP server the local router is passively accepting time from the remote NTP server. Get CPU Usage on remote computers like shown in task manager-Updated shown like in taskmangaer.PowerShell function to get CPU and memory usage of multiple server