-2

I'm interested in finding a solution to take the current time and date using C# and then using that value to set the time and date to set the clock in Linux. This would execute ideally on a button click in Visual Studio Windows Forms and would take the current time and date generated through C# to send that value to Linux OS via a packet. I'm just wondering how to format the value created in C# so that it translates in a way that is relevant by setting the date and time in Linux.

The date and time value is going to be sent to a separate computer running Linux that receives information from the windows based computer via a packet

DateTime now = DateTime.Now;

and then something like

date --set="now"

        
4
  • 1
    windows forms isn't supported on linux. Commented Jan 7, 2022 at 15:57
  • No I know. The date and time value is going to be sent to a separate computer running Linux that receives information from the windows based computer via a packet Commented Jan 7, 2022 at 16:02
  • What exactly means "send that value to Linux OS via a packet"? Do you want to run a separate c# app on the linux computer and set the time in this app or do you want to set the date from the windows machine, e.g. via SSH? Commented Jan 7, 2022 at 17:25
  • Related: stackoverflow.com/questions/30883237/… Commented Jan 7, 2022 at 17:27

1 Answer 1

2

See if this helps at all. I am assuming you already have the ability to send commands to the Linux machine using an SSH library or something similar. Using the total seconds saves you from having to format any complicated date/time string.

long unixSeconds = DateTimeOffset.Now.ToUnixTimeSeconds(); // Need someway to get the total seconds from epoch

string sshCommand =  "date --set @" + unixSeconds.ToString();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.