strtotime equivalent in .NET

后端 未结 6 1180
春和景丽
春和景丽 2020-12-06 08:04

Is there an equivalent of PHP\'s strtotime() function working on .NET Framework. I\'m talking about it\'s capacity to handle strings likes:

  • strtot
6条回答
  •  自闭症患者
    2020-12-06 08:30

    I think you'll have to write your own method.

    "now" is just DateTime.Now.

    "+1 day" would be DateTime.Now.AddDays(1) for example.

    So you'll need to parse your string looking for this type of input and then call the appropriate DateTime method. The fall-through case would be to pass the string through DateTime.Parse(String, IFormatProvider, DateTimeStyles) with different DateTimeStyles.

提交回复
热议问题