Passing a C# DateTime via the Query String

前端 未结 4 2068
猫巷女王i
猫巷女王i 2021-02-05 02:20

I have a C# DateTime object. This object includes both the date and time. I need to pass this information to a REST-based service. My question is, how do I format the DateTime,

4条回答
  •  抹茶落季
    2021-02-05 03:12

    string s = DateTime.ToString("yyyyMMddHHmmssfff")

    Note: fff is milliseconds (you may remove the 'fff' if it is not needed)
    Then convert it back to DateTime using

    DateTime d = DateTime.ParseExact(s, "yyyyMMddHHmmssfff", CultureInfo.InvariantCulture)

提交回复
热议问题