简体   繁体   中英

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.

Thanks

Console.WriteLine(DateTime.Now.ToString("ddMMyyyy"));

yields 02112012

If you need further customer date formatting, this link should be helpful =)

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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM