Js C # Asp php date operations

Source: Internet
Author: User

I. js date operations: Remember: all date strings use '/' as separators. Of course, '-' can be used as separators, however, using '/' can avoid unexpected errors.

1. method for obtaining time (I .e. constructor ):

①: Var myDate = new Date ()
②: Var myDate = new Date (Milliseconds)//MillisecondsIs the number of milliseconds from midnight (UTC) on January 1, January 1, 1970.
③: Var myDate = new Date (Datestring) // Note that the parameter must use a slash (/) as the separator. Otherwise, an error occurs.
④: Var myDate = new Date (Year,Month,Date[,Hours,Minutes,Seconds,MS]) // The content of the brackets is optional
⑤: Var myDate = new Date. parse () // the content of the brackets is optional

The simplest method ① is to obtain the current local time;

Method 2: generate the time according to the input millisecond, which is the number of milliseconds from midnight (UTC) on January 1, January 1, 1970. When printing the output, it should be converted to the local time, so it will take 8 hours, because China's time zone is GMT + 8, it will be 8 hours more than UTC time

Method ③: generate time based on the input date string. Note that the input string type must be separated by the character, when '-' is used for segmentation, the generated time is UTC time. Therefore, the general usage method replaces '-':

Var myDate = new Date ("00:00:01"); // you can remove the hour, minute, and second.

Var myDate = new Date ('1970-3-16 00:00:01 '. replace ("-", "/"); // you can remove the hour, minute, and second.

Method 4 is also very simple; the return is actually an integer, which is the number of milliseconds from midnight (UTC) on January 1, January 1, 1970. The parameter can be a string number, or you can enter a number directly: of course, it can also be mixed with numbers and strings, but it is not recommended;

Var myDate = new Date (2012, 1, 20 );
Var myDate = new Date ("2012", "10", "21", "23", "59", "59 ");

Then you can operate on the date, as shown in the following figure. Add one day to the date:

Var theDate = new Date (myDate );
MyDate. setDate (myDate. getDate () + 1 );
Var sql1 + = "and Addtime <= '" + myDate. getFullYear () + "/" + (myDate. getMonth () + 1) + "/" + myDate. getDate ();

Method ⑤ is very useful. It is generally used to compare the sizes of two dates. The accepted parameters can be date types or strings that can be converted to date types; you can:

Var myDate1 = new Date ("2012", "10", "21", "23", "59", "59 ");
VaR mydate2 = date. parse ("00:00:01". Replace ("-","/"));
VaR mydate3 = date. parse ("00:00:01 ");
VaR mydate4 = date. parse (mydate1 );

ASP method: cdate

If cdate (tjform. jzrq. Value) <cdate (tjform. qsrq. Value) then
Msgbox ("the end date cannot be earlier than the start date ")
Tjform. jzrq. Focus
Exit Function
End if

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.