[英]How to change date format from DD/MM/YYYY or MM/DD/YYYY to YYYY-MM-DD?
[英]How to change date format from yyyy-MM-dd to ddmmyyyy
我需要自动生成预订ID,例如:02112012/1,如果它是02/11/2012的第一个,并且相应地增加了“ /”之后的数字,因此我需要将日期格式从yyyy-MM-dd更改为ddmmyyyy有什么办法可以做到这一点。
谢谢
像这样:
// parse the original string value into DateTime.
DateTime dt = DateTime.ParseExact("2012-11-02", "yyyy-MM-dd",
CultureInfo.CurrentCulture);
// emit to your desired format.
string bookingIdFormattedDate = dt.ToString("ddMMyyyy");
// bookingIdFormattedDate should be "02112012"
干杯。
string dateString = "2012-10-01";
DateTime date = DateTime.ParseExact(dateString, "yyyy-MM-dd", new DateTimeFormatInfo());
string result=date.ToString("ddmmyyyy");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.