Use of Joda-time

Source: Internet
Author: User
Tags current time datetime locale
Joda-time

home:http://joda-time.sourceforge.net/

Javadoc:http://joda-time.sourceforge.net/apidocs/index.html

Look directly at the code, which is in the online and according to the API collation of some examples, when using the example can be
Package Com.yan.joda;  
Import Java.util.Calendar;  
Import Java.util.Date;  
Import Java.util.Locale;  
Import Org.joda.time.DateTime;  
Import Org.joda.time.Days;  
Import Org.joda.time.LocalDate;  
Import Org.joda.time.format.DateTimeFormat;  
  
Import Org.joda.time.format.DateTimeFormatter; public class Jodatest {public static void main (string[] args) {//Initialization time datetime dat  
                  
                Etime=new DateTime (2012, 12, 13, 18, 23,55); Years, months, days, hours, minutes, seconds, milliseconds datetime DT3 = new DateTime (2011, 2, 13, 10, 30, 50, 333);//February 13, 2010 10:30 50 sec 333 mm Seconds//The following is the output time in the form of a little String str2 = datetime.tostring ("mm/dd/yyyy hh: Mm:ss.  
                SSSa ");  
                String STR3 = datetime.tostring ("dd-mm-yyyy HH:mm:ss");  
                String STR4 = datetime.tostring ("eeee dd MMMM, yyyy HH:mm:ssa");  
 String STR5 = datetime.tostring ("mm/dd/yyyy hh:mm ZZZZ");               String STR6 = datetime.tostring ("mm/dd/yyyy hh:mm Z");  
                DateTimeFormatter format = DateTimeFormat. Forpattern ("Yyyy-mm-dd HH:mm:ss");    
                    
                Time resolution DateTime dateTime2 = DateTime.Parse ("2012-12-21 23:22:45", format); Time format, output ==> 2012/12/21 23:22:45 Fri String String_u = datetime2.tostring ("yyyy/mm/    
                DD HH:mm:ss EE ");    
                    
                System.out.println (String_u); Formatted with locale, output ==> December 21, 2012 23:22:45 Friday String string_c = datetime2.tostring ("yyyy mm month DD Day hh:mm    
                : ss EE ", Locale.chinese);  
                  
                System.out.println (String_c); DateTime DT1 = new DateTime ();//Gets the current time//the time string is converted to a DateTime object according to the specified format, where the format and the output format above are The same DateTime DT2 = Datetimeformat.forpattern ("Yyyy-mm-dd HH:mm:ss"). PArsedatetime ("2012-12-26 03:27:39");    
                Calculates the number of days between two date intervals Localdate start=new localdate (2012, 12,14);    
                Localdate End=new Localdate (2013, 01, 15);  
                  
                int days = Days.daysbetween (start, end). GetDays (); Calculates the number of hours, minutes, seconds//increase date of two date interval datetime dateTime1 = DateTime.Parse ("2  
                012-12-03 ");  
                dateTime1 = Datetime1.plusdays (30);  
                dateTime1 = datetime1.plushours (3);  
                dateTime1 = Datetime1.plusminutes (3);  
                dateTime1 = Datetime1.plusmonths (2);  
                dateTime1 = Datetime1.plusseconds (4);  
                dateTime1 = Datetime1.plusweeks (5);  
                  
                dateTime1 = Datetime1.plusyears (3);    
                                    Joda-time various operations ... dateTime = datetime.plusdays (1)//Increase Day . PLusyears (1)//Increase year. Plusmonths (1)//increase month. pl Usweeks (1)//Increase week. Minusmillis (1)//minus minutes. m Inushours (1)//decreases in. minusseconds (1);//minus seconds//    
                Determines whether the leap month datetime DT4 = new DateTime ();    
                Org.joda.time.DateTime.Property month = Dt4.monthofyear ();  
                  
                SYSTEM.OUT.PRINTLN ("Whether leap month:" + month.isleap ());    
                Gets 3 seconds ago DateTime DT5 = Datetime1.secondofminute (). Addtocopy (-3);    
                Datetime1.getsecondofminute ();//Get the whole minute after the number of seconds datetime1.getsecondofday ();//Get the whole day after the number of seconds Datetime1.secondofminute ();//Get minute objects, such as making leap year judgments, etc. use//datetime with Java.util.Date object, current System Timemillis Conversion DatetiMe dt6 = new DateTime (new Date ());    
                Date date = Datetime1.todate ();    
                DateTime DT7 = new DateTime (System.currenttimemillis ());   
                  
                Datetime1.getmillis ();    
                Calendar calendar = Calendar.getinstance ();  
    datetime = new DateTime (calendar);   }


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.