Information management system How to get the current date time

Source: Internet
Author: User

in the process of co-development of charge system of computer room, responsible for writing U layer of H Raises the question of whether the value of that date and time field is obtained from the client program or from the DBMS on the server? To tell you the truth, I did not want to get the current time from the database system before I made the beef Brisket news release system, which made me gain insight. Later in the process of communication, have learned that can also get network time, then today to first of these three kinds of methods to get the current date and time to summarize.

The first is to get the current time from the client program, this is not difficult, I believe we have done this thing, of course, different programming languages may differ, but in general are the same, usually called system functions to obtain. I'll take the C # language as an example, for example:


The second is from DBMS get the current time, this is much simpler, we take SQL Server For example, make a simple example:


It's getting dates and times together. datetime type, if you only want to use the date or time, you will use Convert function. Examples are as follows:


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

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

    Finally, how to get the current date and time from the network, this author does not write the function to get the network time, so look everywhere on the internet, finally find a c# version, and ultimately because url link is inaccessible, failed to achieve the long-cherished wish to gain network time. Later in the search results see Longge's Blog "Multi-Method acquisition Network Time" (blog address: http://blog.csdn.net/ xiaoxian8023/article/details/7250385 " suddenly feel the savior came, so carefully read the blog, and then debug to find the code, found or not. Then just try it next to each other, did not expect the first method to succeed. Everyone to c# Code access to network time is interested in the Dragon Brother's blog to see, the third method of the blog I did not run out, interested can try it yourself.

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


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

Information management system How to get the current date 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.