Click here to Skip to main content
15,888,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am using command prompt and I entered the following command:
--> NET TIME

It returned me the following message:
Current time at......is 2:09:45 PM
The command completed successfully.

As from the message above, the time do not have milliseconds. How can I include also the milliseconds using the same command: NET TIME ?

FYI, I will have the following C# codes to retrieve the above result:
C#
using (Process p = new Process())
        {
         p.StartInfo.UseShellExecute = false;
         p.StartInfo.RedirectStandardOutput = true;
         p.StartInfo.CreateNoWindow = true;
         p.StartInfo.FileName = ConstantReference.General.Net;
         p.StartInfo.Arguments = @value;
         p.Start();
         p.WaitForExit();
         string output = p.StandardOutput.ReadToEnd(); //result here
        }


From the string output above, it do not have milliseconds, how can I make it to have milliseconds? I have tried to search from Internet resources but I can't find the answer.
Any input is appreciated. Thank you.
Posted

1 solution

You can not...
NET TIME used to synchronize your computer's clock with a time server (without additional parameters it will be the DC), that synchronization done on the binary level, but you have no control over the displayed value...
 
Share this answer
 
Comments
Jamie888 19-Apr-15 6:28am    
may I know is there any other command that I can use besides echo %time% to get the time with milliseconds? I need to get server time instead of local PC time(which is the result of echo %time%).
Kornfeld Eliyahu Peter 19-Apr-15 6:58am    
You can create a NTP client (a b it large project): http://dotnet-snippets.com/snippet/simple-network-time-ntp-protocol-client/571
Or you can use WMI to read remote machine: https://msdn.microsoft.com/en-us/library/ms257337(v=vs.80).aspx. The select you have to run is 'SELECT * FROM Win32_LocalTime'...
Jamie888 20-Apr-15 2:35am    
Hi Sir, I have tried using NTP. All is working now but I will keep you updated for any results that I found in the near future. Thank you for your suggestion.
Kornfeld Eliyahu Peter 20-Apr-15 3:11am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900