I am having relative datetime string like:
- “5 minutes ago”
- “10 hours ago”
- “3 days ago” etc.
How can I convert this to exact datetime, as exactly opposite of this question
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This code should work:
It does the parsing of an interval name (such as minute, hour, day) and multiplies them to get the number of minutes because later on it uses
DateTime.Now.AddMinutesmethod, same thing could be done usingTimeSpanand callingDateTime.Now.Add.Here is one more example that handles case of a string that contains more than one interval name, such as “10 hours and 15 minutes ago”: