[英]How to change date format from yyyy-MM-dd to ddmmyyyy
I need to autogenerate booking id, example: 02112012/1 ,if its first of 02/11/2012 and accordingly the number after "/" increases, so for that I need to change date format from yyyy-MM-dd to ddmmyyyy so is there any way i can do this. 我需要自动生成预订ID,例如:02112012/1,如果它是02/11/2012的第一个,并且相应地增加了“ /”之后的数字,因此我需要将日期格式从yyyy-MM-dd更改为ddmmyyyy有什么办法可以做到这一点。
Thanks 谢谢
Like this: 像这样:
// 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"
Cheers. 干杯。
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.