Easy String to DateTime, datetime to String and formatting

Source: Internet
Author: User
Tags month name

String to DateTime
 //String to DateTimeString MyString; MyString="1999-09-01 21:34 PM"; //MyString = "1999-09-01 21:34 p.m."; //Depends on your regional settingsDateTime Mydatetime; Mydatetime=NewDateTime (); Mydatetime= DateTime.ParseExact (MyString,"yyyy-mm-dd hh:mm TT",                                  NULL);
DateTime to String
// DateTime to String New DateTime (1999)= mydatetime.tostring ( " yyyy-mm-dd hh:mm TT ");
Format String for Dates

Your format is string  Your most important key. In the most of my projects, I make it a constant and then refer to the constant value in my code.

The following is the most commonly used format characters:

D-Numeric Day of the month without a leading zero.dd-Numeric Day of the month with a leading zero.ddd-abbreviated name of the day of the WEEK.DDDD-Full name of the day of the week.f,ff,fff,ffff,fffff,ffffff,fffffff-fraction of a second. the more Fs the higher the Precision.h- AHour Clock, no leading zero.hh- AHour clock with leading zero. H- -Hour Clock, no leading zero. HH- -Hour clock with leading ZERO.M-Minutes with no leading zero.mm-Minutes with leading zero. M-Numeric Month with no leading zero. MM-Numeric Month with a leading zero. MMM-abbreviated name of month. MMMM-Full month NAME.S-Seconds with no leading ZERO.SS-Seconds with leading zero.t-am/PM but only the first letter . TT-AM/PM (a.m./p.m.) Y-Year with outcentury and leading zero.yy-Year with outcentury, with leading zero.yyyy-Year with Century.zz-Time zone offSetWith +/-.

Excerpt from: Http://www.codeproject.com/Articles/14743/Easy-String-to-DateTime-DateTime-to-String-and-For

Easy String to DateTime, datetime to String and formatting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.