C#/.NET: How to write today's date/current time in string
Question by CSchaf | 2014-09-01 at 23:42
I would like to determine the current date and time using C# (C-Sharp, .NET Framework) to be able to write it into a string, so that I can work with it.
Later, I would like to store this timestamp together with some other data, but at the moment I am failing at being able to read out the time at all. Does someone have any idea how to do that? Are there any ready built in methods or functions for that?
Related Topics
PHP: Current Date and Time
Tutorial | 0 Comments
MySQL: Write current Date or Time into Column
Tutorial | 0 Comments
JavaScript: Get current Date and Time
Tutorial | 1 Comment
Delphi/Lazarus: Display current Date and Time
Tip | 0 Comments
PHP: Determine Week Number
Tutorial | 0 Comments
PHP: Check Strings with Ctype-Functions for Character Classes
Article | 0 Comments
VirtualBox: Change Date and Time
Tutorial | 10 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
You can use DateTime.Now.ToString to store the current date in the string. Depending on how you would like to format your date and time, you can pass another formatting string:
Hereby, among others, you can use the following format specifiers:
As you can see in the example above, you can also use other characters such as dots or hyphens between the format specifiers like you want.
2014-09-04 at 20:58