As the project progresses, the data transfer and interface are basically completed, and the following are some of the details of the changes
The main content of today's blog is to get the current time and conversion of the same thrift type
Similar to C #, Java also has a time class date, loading the package import java.util.Date;
Instantiating a date
Date time = new Date ();
Use the. Get () method to get the day of the month
int year = Currtime.getyear ();//Years
But in the actual use process found using the. Get () method in the middle there is a horizontal line, Baidu a bit, there is a horizontal line of the future Java API will be removed, in order to facilitate the program can be upgraded, it is best not to use these methods
Date.getyear () is replaced with Calendar.get (calendar.year), and so on, it is worth mentioning that the month in Java is starting from 0, so the obtained month takes +1 to get the actual month
To understand this, the following is the conversion with thrift, thrift can support the type does not include the event type, in the process of access needs conversion, the main function code is as follows:
Public Staticthrift_datetime Thrifttime (Calendar a) {Thrift_datetime time=NewThrift_datetime (); Time.nyear= ( Short) A.get (calendar.year); Time.nmonth= ( Short) (A.get (calendar.month) + 1); Time.nday= ( Short) A.get (calendar.day_of_month); Time.nhour= ( Short) A.get (calendar.hour_of_day); Time.nmin= ( Short) A.get (Calendar.minute); Time.nsec= ( Short) A.get (Calendar.second); returnTime ; }
Javeweb company Projects (5)-----Java Gets the date of the current time and the conversion from the same thrift format