_Csandeep

Joda DateTimeFormatter Example

Jan 24th, 2014 (edited)
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. /**
  2.  * @see http://pastebin.com/tTWVsann
  3.  *
  4.  */
  5. package com.facebook.www.javagroup.NidhiN100001712165293;
  6.  
  7. import java.util.Locale;
  8.  
  9. import org.joda.time.DateTime;
  10. import org.joda.time.format.DateTimeFormat;
  11. import org.joda.time.format.DateTimeFormatter;
  12.  
  13. public class Main {
  14.  
  15.     public static void main(String[] args) {
  16.         DateTime dateTime1 = new DateTime("2014-01-01");
  17.  
  18.         DateTime dateTime2 = new DateTime("14-01-01");
  19.  
  20.         DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MMM-yy")
  21.                 .withLocale(Locale.UK);
  22.  
  23.         String string1 = fmt.print(dateTime1);
  24.  
  25.         String string2 = fmt.print(dateTime2);
  26.  
  27.         System.out.println(string1); // 01-Jan-14
  28.  
  29.         System.out.println(string2); // 01-Jan-14
  30.     }
  31. }
Add Comment
Please, Sign In to add comment