Instance 365 (6) --------- DateTime. ToString format date, use the DateDiff method to obtain the number of Date and Time Intervals

Source: Internet
Author: User
Tags iso 8601

I. DateTime. ToString format date,

Ii. Code
Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. windows. forms; namespace TmrFormat {public partial class Frm_Main: Form {public Frm_Main () {InitializeComponent ();} /* parameter format detailed usage format character Association attributes/description d ShortDatePattern D LongDatePattern f complete date and time (long date and short time) F FullDateTimePattern (long date and long time) g regular (short date and short time) G regular (short date and long time) m, M MonthDayPattern r, R RFC1123Pattern s use local time SortableDateTimePattern (based on ISO 8601) t ShortTimePattern T LongTimePattern u UniversalSortableDateTimePattern is used to display the format of Universal Time U use the complete date and time of Universal Time (long date and long time) y, Y YearMonthPattern */private void btn_GetTime_Click (object sender, EventArgs e) {lab_time.Text = DateTime. now. toString ("d") + "\ n" + // format the DateTime string using the string variable in the specified format. now. toString ("D") + "\ n" + DateTime. now. toString ("f") + "\ n" + DateTime. now. toString ("F") + "\ n" + DateTime. now. toString ("g") + "\ n" + DateTime. now. toString ("G") + "\ n" + DateTime. now. toString ("R") + "\ n" + DateTime. now. toString ("y") + "\ n" + "current system time:" + DateTime. now. toString (// format the string in the custom format "yyyy MM dd HH mm ss seconds ");}}}
3. Use the DateDiff method to obtain the date and time intervals,

4. Code
Using System; using System. windows. forms; using Microsoft. visualBasic; namespace GetDateDiff {public partial class Frm_Main: Form {public Frm_Main () {InitializeComponent ();}/* Parameter Interval Type: Microsoft. visualBasic. dateInterval is required. The DateInterval enumerated value or String expression indicates the time interval between the units to be used as the difference between Date1 and Date2. Date1 type: required by System. DateTime. Date. The first Date/time value to be used in the calculation. Date2 type: required by System. DateTime. Date. The second Date/time value to be used in the calculation. DayOfWeek type: Microsoft. VisualBasic. FirstDayOfWeek is optional. The value selected from the FirstDayOfWeek enumeration to specify the first day of a week. If not specified, use FirstDayOfWeek. Sunday. WeekOfYear type: Microsoft. VisualBasic. FirstWeekOfYear is optional. The value selected from the FirstWeekOfYear enumeration to specify the first week of the year. If not specified, use FirstWeekOfYear. Jan1. Return Value Type: System. Int64 returns a Long value, which specifies the time interval between two Date values. */Private void btn_Get_Click (object sender, EventArgs e) {MessageBox. show ("interval" + DateAndTime. dateDiff (// use the DateDiff method to obtain the date interval DateInterval. day, dtpicker_first.Value, dtpicker_second.Value, FirstDayOfWeek. sunday, FirstWeekOfYear. jan1 ). toString () + "day", "interval ");}}}

 

Related Article

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.