Alex Rivera | Logout

How to parse relative time?

Asked 2008-09-10T22:27:51.143
12

This question is the other side of the question asking, "How do I calculate relative time?".

Given some human input for a relative time, how can you parse it? By default you would offset from DateTime.Now(), but could optionally offset from another DateTime.

(Prefer answers in C#)

Example input:

  • "in 20 minutes"
  • "5 hours ago"
  • "3h 2m"
  • "next week"

Edit: Let's suppose we can define some limits on the input. This sort of code would be a useful thing to have out on the web.

Edit
Report

1 Answer

0

This is likely not all that helpful since you're talking c# but since no one's mentioned it yet you can try to take a look at php's excellent and utterly insane native strtotime function

answered 2008-09-10T23:12:52.500

Your Answer