Skip to content

Instantly share code, notes, and snippets.

@ckurtm
Created February 16, 2016 11:38
Show Gist options
  • Select an option

  • Save ckurtm/2a8cef3c7c809c4e256e to your computer and use it in GitHub Desktop.

Select an option

Save ckurtm/2a8cef3c7c809c4e256e to your computer and use it in GitHub Desktop.

Revisions

  1. ckurtm created this gist Feb 16, 2016.
    33 changes: 33 additions & 0 deletions ThreeTenABP
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    LocalDateTime ldt = LocalDateTime.now();
    int ld = ldt.getDayOfMonth();
    int lm = ldt.getMonthValue();
    int ly = ldt.getYear();
    Log.d(TAG,"3ten : "+ldt.toString());
    Log.d(TAG,"3ten : [day: "+ld+"] [month: "+lm+"] [year: "+ly+"]");
    Log.d(TAG,"3ten : [day: "+ldt.getDayOfWeek().name()+"] [month: "+ldt.getMonth().name()+"] [year: "+ldt.getYear()+"]");


    ldt.withYear(2000);
    ldt.plusHours(2);
    Log.d(TAG,"3ten : " +ldt.toString());


    String frenchShortName = ldt.getMonth().getDisplayName(TextStyle.SHORT,Locale.FRENCH);
    boolean isLeapYear = false; // could not find a matching function
    LocalDateTime rounded = ldt.truncatedTo(ChronoUnit.DAYS);
    Log.d(TAG,"3ten : [french Short: "+frenchShortName+"] [leapyear: "+isLeapYear+"] [rounded: "+rounded+"]");



    ldt = LocalDateTime.of(2005, 3, 26, 12, 0, 0, 0);
    Log.d(TAG,"3ten : "+ ldt.toString());
    LocalDateTime plusPeriod = ldt.plusDays(1);
    Log.d(TAG,"3ten : +1day: "+ plusPeriod.toString());
    LocalDateTime plusDuration = ldt.plus(24,ChronoUnit.HOURS);
    Log.d(TAG,"3ten : +24h : "+ plusDuration.toString());


    LocalDateTime today = LocalDateTime.now();
    LocalDateTime yesterday = today.minusDays(1);
    org.threeten.bp.Duration diff = org.threeten.bp.Duration.between(today,yesterday);
    Log.d(TAG,"3ten : hours between "+ diff.toHours());