Asp.net determines whether to calculate the stock, futures, and gold trading date based on the current time.

Source: Internet
Author: User

A simple method:

Stock: To am from AM to Am from AM to Friday every week

Futures: From to AM, from AM to AM, from PM to AM, from 1 to Friday every week

Gold)

View code

/// <Summary> /// determine whether the current time is the transaction time /// </Summary> /// <Param name = "type"> the transaction type 0 is the stock, 1 For futures, 2 is gold </param> /// <Param name = "DT"> current time </param> /// <returns> </returns> Public static bool _ datatime (int type, datetime DT) {bool _ datatimebool = false; If (_ data (DT) {Switch (type) {Case 0: // stock if (DT> datetime. parse ("9:30") & dt <datetime. parse ("11: 30") | (DT> datetime. parse ("13:00") & dt <datetime. parse ("15:00") _ datatimebool = true; else _ datatimebool = false; break; Case 1: // futures if (DT> datetime. parse ("9:00") & dt <datetime. parse ("11: 30") | (DT> datetime. parse ("13:30") & dt <datetime. parse ("15:00") _ datatimebool = true; else _ datatimebool = false; break; Case 2: // gold if (DT> datetime. parse ("9:00") & dt <datetime. parse ("11: 30") | (DT> datetime. parse ("13:30") & dt <datetime. parse ("") _ datatimebool = true; else _ datatimebool = false; break;} return _ datatimebool ;} /// <summary> /// check whether it is on the opening day /// </Summary> /// <Param name = "DT"> current time </param> // /<returns> </returns> Private Static bool _ data (datetime DT) {bool _ ret = false; Switch (DT. dayofweek) {Case dayofweek. friday: _ ret = true; break; Case dayofweek. monday: _ ret = true; break; Case dayofweek. saturday: _ ret = false; break; Case dayofweek. sunday: _ ret = false; break; Case dayofweek. thursday: _ ret = true; break; Case dayofweek. tuesday: _ ret = true; break; Case dayofweek. wednesday: _ ret = true; break;} return _ ret ;}

 

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.