How the information management system obtains the current date time

Source: Internet
Author: User
Tags local time

In the process of cooperative development of the computer room toll system, the H that is responsible for writing the U layer raises a question as to whether the value of the date and Time field is obtained from the client program or from the DBMS's server when the database record is inserted. To be honest, I did not want to get the current time from the database system before I did the beef Brisket press release system, which made me grow up. Later in the process of communication, there is also a sense of access to the network time, then today to the three to get the current date time of the method for a summary.

The first is to get the current time from the client program, this is not difficult, I believe you have done this thing, of course, there may be differences between different programming languages, but in general are the same, usually call system functions to obtain. Let me take the C # language as an example, for instance:


The second is to get the current time from the DBMS, which is simpler, and we take SQL Server 2008 as an example for a simple example:


It gets the date and time together. DateTime type, if you only want to use the date or time, you need to use the CONVERT function. Examples are as follows:


Of course, there are many forms of format conversion, the details can refer to the following blog:

http://blog.csdn.net/jimlong/article/details/7346970

Finally, how to get the current date time from the network, the author does not write access to the network time function, so look everywhere on the Internet Ah, not easy to find a C # version, finally because the URL link can not access, failed to achieve the long-cherished wish to obtain network time. Later in the search results to see Longge Blog "Multiple methods to get network Time" (blog address: http://blog.csdn.net/xiaoxian8023/article/details/7250385), immediately feel the savior came, so carefully read the blog , and then debug the found code, found that still not. Then simply next to try it, did not think the first method was successful. You are interested in the C # code to get network time to see the blog, the blog on the third Way I did not run out, interested can try their own.

Then I took my computer's time as well, as shown in the following figure:


You can find that the author's computer time is obviously slower than the network time of nearly 3 minutes, therefore, when we do the system, especially the financial system, to write time to the database, should be cautious, can not blindly get the time information from the client, of course, the database server can not, in case the server time is also not allowed. You might say that there is a problem of network latency in getting network time. It does make sense, but network latency is basically in the millisecond level, compared to the more reliable. But this is in the network unobstructed situation, in case of broken net, it is very troublesome. So use a compromise approach, regularly proofread local time, real-time and network synchronization.

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.