Last active
February 16, 2016 11:37
-
-
Save ckurtm/e87d277714b6817efa82 to your computer and use it in GitHub Desktop.
Jodatime quick start
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DateTime dt = DateTime.now(); | |
int jd = dt.getDayOfMonth(); | |
int jm = dt.getMonthOfYear(); | |
int jy = dt.getYear(); | |
Log.d(TAG,"Joda : "+ dt.toString()); | |
Log.d(TAG,"Joda : [day: "+jd+"] [month: "+jm+"] [year: "+jy+"]"); | |
Log.d(TAG,"Joda : [day: "+dt.dayOfWeek().getAsText()+"] [month: "+dt.monthOfYear().getAsText()+"] [year: "+dt.year().getAsText()+"]"); | |
dt.withYear(2000); | |
dt.plusHours(2); | |
Log.d(TAG,"Joda : "+dt.toString()); | |
String frenchShortName = dt.monthOfYear().getAsShortText(Locale.FRENCH); | |
boolean isLeapYear = dt.year().isLeap(); | |
DateTime rounded = dt.dayOfMonth().roundFloorCopy(); | |
Log.d(TAG,"Joda : [french Short: "+frenchShortName+"] [leapyear: "+isLeapYear+"] [rounded: "+rounded+"]"); | |
dt = new DateTime(2005, 3, 26, 12, 0, 0, 0); | |
Log.d(TAG,"Joda : "+ dt.toString()); | |
DateTime plusPeriod = dt.plus(Period.days(1)); | |
Log.d(TAG,"Joda : +1day "+ plusPeriod.toString()); | |
DateTime plusDuration = dt.plus(new Duration(24L*60L*60L*1000L)); | |
Log.d(TAG,"Joda : +24h "+ plusDuration.toString()); | |
DateTime today = DateTime.now(); | |
DateTime yesterday = today.minusDays(1); | |
Hours diff = Hours.hoursBetween(today,yesterday); | |
Log.d(TAG,"Joda : hours between "+ diff.getHours()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment