Javeweb company Projects (5)-----Java Gets the date of the current time and the conversion from the same thrift format

Source: Internet
Author: User

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

Related Article

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.