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.