Skip to content

Instantly share code, notes, and snippets.

@ainvyu
Created December 29, 2015 02:56
Show Gist options
  • Save ainvyu/4b2f190b3379dfaadb00 to your computer and use it in GitHub Desktop.
Save ainvyu/4b2f190b3379dfaadb00 to your computer and use it in GitHub Desktop.
Date sample rev.2
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
/**
* Created by vine on 15. 5. 27..
*/
public class Main {
public static void main(String args[]) {
String pattern = "yyyyMMdd";
String thisTimeZone = DateTimeZone.UTC.getID(); //"UTC";
DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern)
.withZone(DateTimeZone.forID(thisTimeZone));
DateTime dateTime = formatter.parseDateTime("20160101").plusMonths(-1);
System.out.println(dateTime.dayOfMonth().getMaximumValue());
List<String> days = new ArrayList<String>();
for (int i = 0; i < dateTime.dayOfMonth().getMaximumValue(); ++i) {
DateTime targetDateTime = dateTime.plusDays(i);
days.add(formatter.print(targetDateTime));
}
System.out.println(days);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment