How does the information management system obtain the current date and time?

Source: Internet
Author: User

How does the information management system obtain the current date and time?

During the cooperative development of the data room charging system, H in charge of compiling the U layer raised a question. When we insert database records, is the value of the date and time field obtained from the client program or from the DBMS server? To be honest, I didn't think about getting the current time from the database system before I was working on the niugu news and publishing system, which gave me more insights. Later, during the communication, I learned that the network time can be obtained. Today, I will summarize the three methods for obtaining the current date and time.

The first step is to get the current time from the client program. It is not difficult. I believe everyone has done this. Of course, there may be differences between different programming languages, but they are all the same in general, it is usually obtained by calling system functions. The following uses the C # language as an example:


The second is to obtain the current time from the DBMS. This is simpler. We take SQL Server 2008 as an example:


The date and time obtained above are of the datetime type. If you only want to use the date or time, you must use the convert function. Example:


Of course, there are many formats for conversion. For details, refer to the following blog:

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

Finally, let's talk about how to get the current date and time from the network. The author will not write a function to get the network time. So I can find a C # version on the Internet, in the end, the network time cannot be obtained because the URL link cannot be accessed. Later in the search results to see long brother's blog "multi-way get Network Time" (blog address: http://blog.csdn.net/xiaoxian8023/article/details/7250385), suddenly feel the rescue, so carefully read the blog, and then debug the code to find that it still does not work. Later, just try again. I didn't expect the first method to succeed. If you are interested in the C # code to obtain the network time, you can go to longge's blog to see it. The third method in the blog is not running. If you are interested, try it on your own.

Then I acquired the time of my computer, as shown in:

When writing data to a database, you should be careful not to obtain the time information from the client. Of course, the database server cannot. What if the server's time is not accurate? You may say that there is a network delay problem in obtaining the network time. It does make sense, but the network latency is basically at the millisecond level, which is comparatively reliable. However, in the case of a network disconnection, isn't it very troublesome? Therefore, we adopt a compromise method to regularly check local time and synchronize it with the network in real 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.