Open Source Java Time Tool class Joda-time experience

Source: Internet
Author: User

Tags: java

import org.joda.time.*;import org.joda.time.format.datetimeformat;import  org.joda.time.format.datetimeformatter;import org.junit.test;import java.util.locale;/** *   @author  by lei zhou on 2017/11/09 14:20. */public class  jodatimetest {     @Test     public void test ()  {         //  Date output Format          Datetimeformatter datetimeformat = datetimeformat.forpattern ("Yyyy-MM-dd HH:mm:ss");         system.out.println ("Current datetime: "  + datetime.now (). ToString (DateTimeFormat));         system.out.println ("Current date but time clear 0:  " + datetime.now (). Withtimeatstartofday (). toString (DateTimeFormat));         system.out.println ("Date and time of the first Sunday of this month:  " + getthismonthfirstsunday (). toString (DateTimeFormat));       &NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("This week Monday datetime: "  + getthisweeksunday (). toString (DateTimeFormat));         system.out.println ("Days from New Year's Day: "  + daystonewyear ( DateTime.Now ());         system.out.println (":  from New Year months"  +  monthstonewyear (DateTime.Now ()));         string[] french  = datetimeutils.getdateformatsymbols (locale.france). Getweekdays ();         string[] japanese = datetimeutils.getdateformatsymbols (Locale.JAPAN). Getweekdays ();        string[] korean =  Datetimeutils.getdateformatsymbols (Locale.korea). Getweekdays ();         system.out.println ("The first day of the month is the Week: ");         for  (int month = 1; month <= 12 ;  month++)  {            DateTime  Monthdatetime = datetime.now (). Withtimeatstartofday (). Withmonthofyear (month). Withdayofmonth (1);             int index =  Monthdatetime.dayofweek (). Get ()  % 7 + 1;             system.out.println (Monthdatetime.tostring (Datetimeformat.fulldatetime ())  +  "   French: " + french[index] + "   Japanese: " + japanese[index] + "   Korean : " + korean[index]);        }    }     private int monthstonewyear (datetime fromdate)  {         datetiMe newyear = fromdate.plusyears (1). Withdayofyear (1);         return months.monthsbetween (fromdate, newyear). Getmonths ();    }     private int daystonewyear (datetime fromdate)  {         datetime newyear = fromdate.plusyears (1). WithDayOfYear (1);         return days.daysbetween (fromdate, newyear). GetDays ();     }    private datetime getthismonthfirstsunday ()  {         return datetime.now (). Withdayofmonth (1). WithDayOfWeek ( Datetimeconstants.sunday);    }    private datetime  Getthisweeksunday ()  {        return datetime.now (). Withdayofweek (datetimeconstants.monday);      }} 

Output Result:

Current datetime:  2017-11-09 16:01:36 current date but time clear 0: 2017-11-09 00:00:00 date and time of the first Sunday of the month:  2017-11-05  16:01:36 Monday datetime:  2017-11-06 16:01:36 from New Year's Day:  53 distance from New Year months:  1 this year the first of the month is the week:  2017 year January 1   Sunday   12:00 A.M. 00 sec  CST  French:dimanche  Japanese: Sun day   Korean: February 1, 2017   Wednesday   12:00 A.M. 00 seconds  CST  French:mercredi  Japanese: Wednesday   Korean: March 1, 2017   Wednesday   12:00 A.M. 00 sec.  CST  French: mercredi   Japanese: Wednesday   Korean: April 1, 2017   Saturday   12:00 A.M. 00 sec.  CST  French:samedi  Japanese: Earth Day   Korean: May 1, 2017   Monday   12:00 A.M. 00 sec  CST  French:lundi  Japanese: Sun day   Korean: June 1, 2017   Thursday   12:00 A.M. 00 seconds  CST  French:jeudi  Japanese: Thursday   Korean: July 1, 2017   Saturday   12:00 A.M. 00 sec.  CST  French:samedi  Japanese: Earth Day   Korean: August 1, 2017   Tuesday   12:00 A.M. 00 sec  CST  French:mardi  Japanese: Fire day   Korean: September 1, 2017   Friday   12:00 A.M. 00 sec  CST  French:vendredi  Japanese: Kim Buzhi   Korean: October 1, 2017   Sunday   12:00 A.M. 00 sec.   cst  French:dimanche  DayLanguage: Day   Korean: November 1, 2017   Wednesday   12:00 A.M. 00 sec  CST  French:mercredi  Japanese: Wednesday   Korean: December 1, 2017   Friday   12:00 A.M. 00 sec  CST  French:vendredi  Japanese: Kim Buzhi   Korean:


This article is from the "zl1030 Records" blog, so be sure to keep this source http://zl1030.blog.51cto.com/274507/1980326

Open Source Java Time Tool class Joda-time experience

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.

Tags Index: