I have created an API end-point. The caller may call the API with POST
method passing the relevant parameters. In the parameters there is one parameter that is of datetime
format.
The problem is that when calling this API the caller may passes datetime
in 3 different formats:
long int
- e.g. 1374755180- US format - e.g. "7/25/2013 6:37:31 PM" (as
string
) - Timestamp format - e.g. "2013-07-25 14:26:00" (as
string
)
I have to parse the datetime
value and convert it to a DateTime
or string
in Timestamp format.
I have tried using DateTime.TryParse()
, DateTime.Parse()
, Convert.ToDateTime()
and Convert.ToDouble()
but none of them are working in certainty for me.
The required output has to be in en-GB
format.
Edit:
I had thought to have an if-else if-else
block to use with TryParse
3 times with one else
to say the string could not be parsed. Is this the best solution? Or are there solutions better than this?
Please help!