1. 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 Chinese year, month, and day
String strYMD = currentTime. ToString ("D ");
1.13 get the current time, format: 14: 24
String strT = currentTime. ToString ("t ");
1.14 obtain the current time in the format of 2003-09-23T14: 46: 48
String strT = currentTime. ToString ("s ");
1.15 obtain the current time in the format of 2003-09-23 14: 48: 30Z
String strT = currentTime. ToString ("u ");
1.16 The current time. format:
String strT = currentTime. ToString ("g ");
1.17 take the current time, format: Tue, 23 Sep 2003 14:52:40 GMT
String strT = currentTime. ToString ("r ");
1.18 obtain the date and time of the current time n days later
DateTime newDay = DateTime. Now. AddDays (100 );
1. 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 ");
2. Convert string type to 32-digit font
Int32.Parse (variable) Int32.Parse ("constant ")
3. Variable. ToString ()
Convert string to string
12345. ToString ("n"); // generate 12,345.00
12345. ToString ("C"); // generate $12,345.00
12345. ToString ("e"); // generate 1.234500e + 004
12345. ToString ("f4"); // generate 12345.0000
12345. ToString ("x"); // generate 3039 (hexadecimal)
12345. ToString ("p"); // generate 1,234,500.00%
4. Variable. Length numeric type
String Length:
For example, string str = "China ";
Int Len = str. Length; // Len is a custom variable, and str is the variable name of the string to be tested.
5. Convert the character code into a bit code
System. Text. Encoding. Default. GetBytes (variable)
For example, byte [] bytStr = System. Text. Encoding. Default. GetBytes (str );
Then we can get the bit length:
Len = bytStr. Length;
6. System. Text. StringBuilder ("")
String addition, (is the same as the + number ?)
For example:
System. Text. StringBuilder sb = new System. Text. StringBuilder ("");
Sb. Append ("China ");
Sb. Append ("people ");
Sb. Append ("Republic ");
7. Variable. Substring (parameter 1, parameter 2 );
Part of the string to be truncated. Parameter 1 is the start number of digits on the left, and parameter 2 is the number of digits to be truncated.
For example, string s1 = str. Substring );
8. Obtain the IP address of a remote user.
String user_IP = Request. ServerVariables ["REMOTE_ADDR"]. ToString ();
9. Obtain the real IP address of the remote user through the proxy server:
If (Request. ServerVariables ["HTTP_VIA"]! = Null ){
String user_IP = Request. ServerVariables ["HTTP_X_FORWARDED_FOR"]. ToString ();
} Else {
String user_IP = Request. ServerVariables ["REMOTE_ADDR"]. ToString ();
}
10. Access Session Value
Session ["variable"];
For example, assign a value:
Session ["username"] = "Bush ";
Valid value:
Object objName = Session ["username"];
String strName = objName. ToString ();
Clear:
Session. RemoveAll ();
11. Send variables with hyperlinks
String str = Request. QueryString ["variable"];
For example, create a hyperlink on any page: <a href = Edit. aspx? Fbid = 23> click </a>