C # obtain the current system time

Source: Internet
Author: User

-- Datetime numeric type <br/> system. datetime currenttime = new system. datetime (); <br/> returns the current year, month, day, hour, minute, and second currenttime = system. datetime. now; <br/> the current year int year = currenttime. year; <br/> use the current month int month = currenttime. month; <br/> use the current day int day = currenttime. day; <br/> when taking the current int value = currenttime. hour; <br/> returns the current int point = currenttime. minute; <br/> takes the current second int seconds = currenttime. second; <br/> the current millisecond int millisecond = currenttime. millisecond; (the variable can be in Chinese) <br/> display the variable on a Chinese Date-year, month, day, And hour St Ring stry = currenttime. tostring ("F"); // seconds not displayed <br/> display date in Chinese _ year and month string strym = currenttime. tostring ("Y"); <br/> use the Chinese date to display the _ month-day string strmd = currenttime. tostring ("M"); <br/> the current year, month, and day. Format: 2003-9-23 string strymd = currenttime. tostring ("D"); <br/> the current time, in the format of 14: 24 string strt = currenttime. tostring ("T"); <br/> datetime. now. tostring (); // obtain the complete date and time of the current system time <br/> datetime. now. tolongdatestring (); // only display the date XXXX-XX-xx, a long date <br /> Datetime. now. toshortdatestring (); // only the date XXXX-XX is a short date <br/> // Today datetime. now. date. toshortdatestring (); <br/> // datetime of yesterday. now. adddays (-1 ). toshortdatestring (); <br/> // tomorrow's datetime. now. adddays (1 ). toshortdatestring (); </P> <p> // This Week (note that every week starts from Sunday to Saturday) <br/> datetime. now. adddays (convert. todouble (0-convert. toint16 (datetime. now. dayofweek )))). toshortdatestring (); <br/> datetime. now. adddays (convert. Todouble (6-convert. toint16 (datetime. now. dayofweek )))). toshortdatestring (); <br/> // last week, last week is the week minus seven days <br/> datetime. now. adddays (convert. todouble (0-convert. toint16 (datetime. now. dayofweek)-7 ). toshortdatestring (); <br/> datetime. now. adddays (convert. todouble (6-convert. toint16 (datetime. now. dayofweek)-7 ). toshortdatestring (); <br/> // Add seven days to the week next week <br/> datetime. now. adddays (convert. todouble (0-C Onvert. toint16 (datetime. now. dayofweek) + 7 ). toshortdatestring (); <br/> datetime. now. adddays (convert. todouble (6-convert. toint16 (datetime. now. dayofweek) + 7 ). toshortdatestring (); <br/> // the first day of this month is the 1st day, and the last day is the 1st day of the month. <Br/> datetime. now. year. tostring () + datetime. now. month. tostring () + "1"; // The first day <br/> datetime. parse (datetime. now. year. tostring () + datetime. now. month. tostring () + "1 "). addmonths (1 ). adddays (-1 ). toshortdatestring (); // The Last Day <br/> another method: <br/> datetime now = datetime. now; <br/> datetime d1 = new datetime (now. year, now. month, 1); // the first day of the month <br/> datetime D2 = d1.addmonths (1 ). adddays (-1); // the last day of the month <br/> PS: <br/> Datetime. now. dayofweek. tostring (); // weekly display in English, Wednesday <br/> (INT) datetime. now. dayofweek number. If it is Wednesday, the result is 3 <br/> datetime. now. tostring ("dddd", new system. globalization. cultureinfo ("ZH-CN"); // week display in Chinese <br/> datetime. now. tostring ("dddd"); // week display in Chinese <br/> datetime. now. tostring ("dddd, Mmmm, DD, YYYY", new system. globalization. datetimeformatinfo (); // display Date Format: Friday, July, 01,2009 <br/> datetime. now. tostring ("dddd, DD m Mmm, YYYY ") // output Wednesday, January, 2008 <br/> Source: http://msdn.microsoft.com/zh-cn/vstudio/bb762911 (vs.95 ). aspx, how to: extract the day of the week from a specific date <br/> datetime type in tostring () format setting <br/> detailed format usage of the parameter <br/> /</description <br/> D shortdatepattern <br/> D longdatepattern <br/> F complete date and time (long date and short time) <br/> F fulldatetimepattern (long date and long time) <br/> G General (short date and short time) <br/> G General (short date and long time) <br/> M, M monthdaypattern <br/> R, R rfc1123pattern <br/> S uses sortabledatetimepattern of the local time (based on ISO 8601) <br/> T shorttimepattern <br/> T longtimepattern <br/> U universalsortabledatetimepattern is used to display the format of universal time <br/> U uses the complete date and time of Universal Time (long date) and long time) <br/> Y, y yearmonthpattern <br/> The following table lists the modes that can be merged to build a custom mode. These modes are case-sensitive <br/> A Day In D month. A single-digit date has no leading zero. <Br/> A Day In DD month. A single-digit date has a leading zero. <Br/> the abbreviated name of a day in DDD Week, which is defined in abbreviateddaynames. <Br/> the full name of a day in the dddd Week, which is defined in daynames. <Br/> M month number. One-digit month does not have a leading zero. <Br/> MM month number. A single-digit month has a leading zero. <Br/> the abbreviated name of the mmm month is defined in abbreviatedmonthnames. <Br/> the full name of the mmmm month, which is defined in monthnames. <Br/> Y does not contain the year of the epoch. If the year that does not contain the epoch is less than 10, the year that does not have the leading zero is displayed. <Br/> YY does not contain the year of the epoch. If the year that does not contain the epoch is less than 10, the year with the leading zero is displayed. <Br/> yyyy includes the four-digit year of the epoch. <Br/> GG period or epoch. This mode is ignored if the date to be formatted does not have an associated period or epoch string. <Br/> hours in H 12-hour format. One-digit hours do not have a leading zero. <Br/> the hour in HH 12-hour format. The number of hours in a single digit has a leading zero. <Br/> hour in H 24-hour format. One-digit hours do not have a leading zero. <Br/> Hh hour in 24-hour format. The number of hours in a single digit has a leading zero. 

From: http://hi.baidu.com/kenstime/blog/item/0a0248b1d3ab78acd9335a94.html

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.