Can parse date DateTime.Parse [duplicate] - c#

This question already has answers here:
Parse string to DateTime in C#
(9 answers)
Closed 6 months ago.
This line is parsed DateTime.Parse("08/08/2000 00:00:00")
This line isn't parsed DateTime.Parse("08/24/2000 00:00:00")
Question is very simple and stupid, I'm sorry but can't figure out why.

This is likely a localization issue, where it's trying to parse in day/month/year format, and you're assuming it's month/day/year format.

Related

C# - Parse Process.StartTime to a certain format [duplicate]

This question already has answers here:
C# DateTime to "YYYYMMDDHHMMSS" format
(18 answers)
DateTime ParseExact string was not recognize as a DateTime C#
(2 answers)
Closed 4 months ago.
I can't figure a way to parse a Datetime object that is "10/24/2022 4:01:35 PM" to "24/10/2022 16:01:35".
Can't find an answer for this exact format.
Thanks in advance!
I guess you don't need to parse that string to DateTime since you have it already in Process.StartTime and you're looking at it in the debugger. Then use it directly. If you really have it as string you simply need to use DateTime.Parse with InvariantCulture:
DateTime dt = DateTime.Parse("10/24/2022 4:01:35 PM", System.Globalization.CultureInfo.InvariantCulture);
and for the output:
Console.Write(dt.ToString("dd'/'MM'/'yyyy HH:mm:ss"));

Convert Date format C# [duplicate]

This question already has answers here:
How do you convert epoch time in C#?
(14 answers)
Closed 2 years ago.
I am working with an API that requires a certain type of Date format. The date example I am being provided is 10/1/2020 and it converts to 1601528400000. I have never used this type of date before and completely puzzled on what it could be. Does anyone know what type of date format this is?
Example of the URL: https://www.test.org/exports?s_id=-100&g_id=-100&c_id=-100&start_date=1601528400000&end_date=1602478800000
https://currentmillis.com/
DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()

How can we obtain date time format in yyyy.MM.dd [duplicate]

This question already has answers here:
C# DateTime to "YYYYMMDDHHMMSS" format
(18 answers)
Closed 4 years ago.
How can we obtain the current date in format yyyy.MM.dd in C# ASP.NET?
using DateTime.Now
Simply by using
string date = DateTime.Now.ToString("yyyy.MM.dd");
See this documentation for more info on custom date and time formats.

Why is this throwing System.FormatException:String was not recognized as a valid DateTime [duplicate]

This question already has answers here:
Parse string to DateTime in C#
(9 answers)
Closed 5 years ago.
Why does this:
Convert.ToDateTime("08/31/2017")
throw an System.FormatException but not this:
Convert.ToDateTime("09/12/2017")
If you need more information please ask and I will update or comment. I have no clue what is causing this issue, so I don't know what details you need.
The default order for this date format on your computers culture is Day/Month/Year, as 31 is not a valid month it fails. If you want this order, you need to provide the format with it:
var x = DateTime.ParseExact("08/31/2017", "MM/dd/yyyy",CultureInfo.InvariantCulture);

Convert String to Date only in C# [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Convert String to Date in .NET
I new here, I'm stuck with this problem when a have an array of strings with values of "120612" and "200612".
I need to convert the strings to a date format like this, "Tues 12 June, 2012". How will I do that?
Thanks in advance.
DateTime.ParseExact is probably what you're looking for:
DateTime.ParseExact("200612", "ddMMyy", System.Globalization.CultureInfo.CurrentCulture)

Categories