Custom date formatting a hole in the string, and last night we had a midnight time.

Source: Internet
Author: User

(First spit groove, just a new add essay when actually did not appear in the Editor tool, the results of the article after saving no typesetting format, not intentionally I do not fragment ah. )

Last night was very sad, busy to 12 o ' night, finally found to be the date time format of the time format specifier to the pit.

The cause of the matter is simple, there is a DataWindow control on the page to accept a date string to refresh the data, the local test is properly measured, how many brushes the data brush, how many new additions, but after the deployment to the server damndest, the data can be added, but the calculated value is zero.

Because the new data under the control to be refreshed first to do the basis of the data to do the operation, so at first we thought it was the calculation of data when the problem, but the server is a formal environment, no VS, nor allow remote debugging, so we have to modify the code, the data in the process of the formula and values, etc. The results are very depressed, the formula is correct, but the source base value is 0, which indicates that the formula calculation is not a problem, the data source is a problem.

So continue to change the code, the number of DataWindow output to the log, and finally found that the control does not load any data, without the basic data, the subsequent calculation data is naturally all 0. But why there is no data, obviously in the local test is foolproof, at this time is close to midnight at 11, we are nearly collapsed.

Finally thought, this control to accept a date string, will it be the problem? The code has been changed n times, recording n many of the original thought error information, and then add a date string output. This time we finally found the hole, the test results found that the date string did not output in the expected format! It's a pit! But why are we testing locally? You can take a look at our date format string code:

DateTime.Now.ToString ("Yyyy/mm/dd");

Do you think it would output a string like "2015/03/17"? Congratulations, you fell into the pit as well as we did.

In fact, on different machines will be output not the same format, is generally "2015/03/17", "2015-03-17" or "2015.03.17" one of the, certainly not exactly as expected output "2015/03/17" format.

Finally, with the help of the almighty Baidu, finally know that this pit hidden too deep, the source is that the date format string, the character "/" is not an ordinary character, but an escape character, which represents the system date format defined in the delimiter. That is, if your system date delimiter is defined as "-" or "." Will output "2015-03-17" or "2015.03.17" instead of "2015/03/17". After the custom format delimiter for the system date on the server and on the computer, it is found that the default delimiter is not the same, the local is "/", and the server is "-", so the same format code has a different format.

This is the problem of the collapse of the last thing is an escape, but it consumes us half a night, sometimes it is so, the result is very simple process is very tortuous. It seems that some of the details of the knowledge still need to be well studied, then how to let the "/" output in the date format string without changing the system settings? The code is as follows:

DateTime.Now.ToString ("Yyyy\\/mm\\/dd");

Custom date formatting a hole in the string, and last night we had a midnight time.

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.