1. get the current system time and date and format the output:
Import JAVA . util. date;
Import JAVA . text. simpledateformat;
public class nowstring {
Public static void main (string [] ARGs) {
simpledateformat df = new simpledateformat ("yyyy-mm-dd hh: MM: SS "); // set the date format
system. out. println (DF. format (new date (); // new date () to obtain the current system time
}< BR >}
2. the date in the database is only output in the form of year-month-day. You can use the following two methods:
1. Convert functions using convert:
String sqlst = "select convert (varchar (10), bookdate, 126) as convertbookdate from roombook where bookdate Between '2014-4-10 'and '2014-4-25 '";
System. Out. println (Rs. getstring ("convertbookdate "));
2. Use the simpledateformat class:
Enter twoJavaPackage:
ImportJava. Util. date;
ImportJava. Text. simpledateformat;
Then:
Defines the Date Format: simpledateformat SDF = new simpledateformat (yy-mm-dd );
SQL statement: String sqlstr = "select bookdate from roombook where bookdate between '2017-4-10 'and '2017-4-25 '";
Output:
System. Out. println (DF. Format (Rs. getdate ("bookdate ")));
Public static string nowtime () {calendar c = calendar. getinstance (); C. settimeinmillis (new date (). gettime (); simpledateformat dateformat = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); Return dateformat. format (C. gettime ());}
Http://blog.sina.com.cn/s/blog_9d708b4f01015480.html