-- Datetime numeric type
System. datetime currenttime = new system. datetime ();
1.1 take the current year, month, day, hour, minute, second
Currenttime = system. datetime. now;
1.2 get current year
Int year = currenttime. Year;
1.3 take the current month
Int month = currenttime. month;
1.4 get the current day
Int day = currenttime. Day;
1.5 current time
Int = currenttime. hour;
1.6 get the current score
Int = currenttime. minute;
1.7 takes the current second
Int second = currenttime. Second;
1.8 takes the current millisecond
Int millisecond = currenttime. millisecond;
(The variable can be in Chinese)
1.9 display Chinese date -- year, month, and day
String stry = currenttime. tostring ("F"); // seconds not displayed
1.10 use Chinese date to display _ year and month
String strym = currenttime. tostring ("Y ");
1.11 retrieve Chinese Date display _ month/day
String strmd = currenttime. tostring ("M ");
1.12 take the current year, month, and day in the format of 2003-9-23
String strymd = currenttime. tostring ("D ");
1.13 get the current time, format: 14: 24
String strt = currenttime. tostring ("T ");
// Today
Datetime. Now. Date. tow.datestring ();
// Yesterday, that is, one minus today's date
Datetime. Now. adddays (-1). tow.datestring ();
// Tomorrow, similarly, add one
Datetime. Now. adddays (1). tow.datestring ();
// This Week (to know the first day of this week, you must first know the day of the week, so that the first day of this week is the day of the day a few days ago, note that every week starts from Sunday to Saturday.
Datetime. Now. adddays (convert. todouble (0-convert. toint16 (datetime. Now. dayofweek). toshortdatestring ();
Datetime. Now. adddays (convert. todouble (6-convert. toint16 (datetime. Now. dayofweek). toshortdatestring ();
// If you still don't understand it, you should understand how to display the day of the week in Chinese.
// Because dayofweek returns the day of the week of the number, we need to convert it into Chinese characters for us to read. Some may use the switch to compare them one by one, in fact, you don't need to bother string [] day = new string [] {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday ", "Saturday "};
Day [convert. toint16 (datetime. Now. dayofweek)];
// Last week. Similarly, a week is 7 days. Last week is the week minus 7 days. The same is true for next week.
Datetime. Now. adddays (convert. todouble (0-convert. toint16 (datetime. Now. dayofweek)-7). toshortdatestring ();
Datetime. Now. adddays (convert. todouble (6-convert. toint16 (datetime. Now. dayofweek)-7). toshortdatestring ();
// Next week
Datetime. Now. adddays (convert. todouble (0-convert. toint16 (datetime. Now. dayofweek) + 7). toshortdatestring ();
Datetime. Now. adddays (convert. todouble (6-convert. toint16 (datetime. Now. dayofweek) + 7). toshortdatestring ();
// This month, many people will say that the first day of this month must be the first day of the month, and the last day is the second day of the month. Of course this is correct
// General statement
Datetime. Now. year. tostring () + datetime. Now. Month. tostring () + "1"; // The first day
Datetime. parse (datetime. now. year. tostring () + datetime. now. month. tostring () + "1 "). addmonths (1 ). adddays (-1 ). toshortdatestring (); // last day
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