本文整理汇总了Java中org.joda.time.MonthDay类的典型用法代码示例。如果您正苦于以下问题:Java MonthDay类的具体用法?Java MonthDay怎么用?Java MonthDay使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MonthDay类属于org.joda.time包,在下文中一共展示了MonthDay类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNextAnniversary
import org.joda.time.MonthDay; //导入依赖的package包/类
/**
* Gets the anniversary date not yet passed (with delta of 1 day)
* @param date Date
* @return Next anniversary in the year
*/
public static Date getNextAnniversary(Date date) {
DateTime dateTimeNow = DateTime.now();
MonthDay monthDayNow = MonthDay.now();
MonthDay monthDayOfNextDate = MonthDay.fromDateFields(date);
if(monthDayNow.isEqual(monthDayOfNextDate)) {
DateTime inputDate = new DateTime(date);
return dateTimeNow
.withHourOfDay(inputDate.getHourOfDay())
.withMinuteOfHour(inputDate.getMinuteOfHour())
.withSecondOfMinute(inputDate.getSecondOfMinute())
.withMillisOfSecond(inputDate.getMillisOfSecond()).toDate();
} if(monthDayNow.isBefore(monthDayOfNextDate))
return new DateTime(date).withYear(dateTimeNow.getYear()).toDate();
else {
DateTime dateTimeOfNextDate = new DateTime(date).withYear(dateTimeNow.getYear()).plusYears(1);
return dateTimeOfNextDate.toDate();
}
}
示例2: extractMonthDayNamed
import org.joda.time.MonthDay; //导入依赖的package包/类
public MonthDay extractMonthDayNamed(final String parameterName, final JsonElement element) {
MonthDay value = null;
if (element.isJsonObject()) {
final JsonObject object = element.getAsJsonObject();
final String monthDayFormat = extractMonthDayFormatParameter(object);
final Locale clientApplicationLocale = extractLocaleParameter(object);
value = extractMonthDayNamed(parameterName, object, monthDayFormat, clientApplicationLocale);
}
return value;
}
示例3: daysBetweenTodayAnd
import org.joda.time.MonthDay; //导入依赖的package包/类
/**
* Return number of days between today and the next date in a year
* @param date date for calculate delta
* @return Number of days always >= 0
*/
public static int daysBetweenTodayAnd(Date date) {
MonthDay monthDayNow = MonthDay.now();
MonthDay monthDayOfNextDate = MonthDay.fromDateFields(date);
if(monthDayNow.isEqual(monthDayOfNextDate))
return 0;
if(monthDayNow.isBefore(monthDayOfNextDate))
return Days.daysBetween(monthDayNow, monthDayOfNextDate).getDays();
else {
DateTime dateTimeNow = DateTime.now();
DateTime dateTimeOfNextDate = new DateTime(date).withYear(dateTimeNow.getYear()).plusYears(1);
return Days.daysBetween(DateTime.now(), dateTimeOfNextDate).getDays();
}
}
示例4: buildBirthday
import org.joda.time.MonthDay; //导入依赖的package包/类
private Birthday buildBirthday(ContentResolver contentResolver, Cursor c) {
String birthDate = c.getString(1);
if (birthDate == null) return null;
// Analyze birthday string
try {
Matcher regexMatcher = regexDate.matcher(birthDate);
if (regexMatcher.find()) {
Birthday birthday = new Birthday(contentResolver, c.getLong(0));
// Birthday *must* have a display name
if (birthday.displayName == null) return null;
birthday.birthdayDate = new MonthDay(
Integer.parseInt(regexMatcher.group(2)),
Integer.parseInt(regexMatcher.group(3))
);
if (!"-".equals(regexMatcher.group(1))) {
birthday.year = Integer.parseInt(regexMatcher.group(1));
birthday.unknownYear = false;
}
return birthday;
}
}
catch (Exception e) {
Log.e(TAG, "Error while analyzing birthday", e);
return null;
}
return null;
}
示例5: read
import org.joda.time.MonthDay; //导入依赖的package包/类
@Override
public MonthDay read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return MonthDay.parse(in.nextString());
}
示例6: creates_instance_of_MonthDay
import org.joda.time.MonthDay; //导入依赖的package包/类
@Test
public void creates_instance_of_MonthDay() {
MonthDay monthDay = fixture.create(MonthDay.class);
assertThat(monthDay, notNullValue());
assertThat(monthDay.getMonthOfYear(), is(1));
assertThat(monthDay.getDayOfMonth(), is(1));
}
示例7: deserialize
import org.joda.time.MonthDay; //导入依赖的package包/类
@Override
public MonthDay deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException, JsonProcessingException {
String str = p.getText().trim();
if (str.isEmpty()) {
return null;
}
return MonthDay.parse(str, formatter);
}
示例8: extractMonthDayNamed
import org.joda.time.MonthDay; //导入依赖的package包/类
public MonthDay extractMonthDayNamed(final String parameterName, final JsonElement element) {
return this.helperDelegator.extractMonthDayNamed(parameterName, element);
}
示例9: parse
import org.joda.time.MonthDay; //导入依赖的package包/类
@Override
public MonthDay parse(String text, Locale locale) throws ParseException {
return MonthDay.parse(text);
}
示例10: print
import org.joda.time.MonthDay; //导入依赖的package包/类
@Override
public String print(MonthDay object, Locale locale) {
return object.toString();
}
示例11: registerAdditionalFormatters
import org.joda.time.MonthDay; //导入依赖的package包/类
public static void registerAdditionalFormatters(FormatterRegistry registry) {
registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());
}
示例12: getMonthDay
import org.joda.time.MonthDay; //导入依赖的package包/类
public MonthDay getMonthDay() {
return monthDay;
}
示例13: setMonthDay
import org.joda.time.MonthDay; //导入依赖的package包/类
public void setMonthDay(MonthDay monthDay) {
this.monthDay = monthDay;
}
示例14: testSerialization
import org.joda.time.MonthDay; //导入依赖的package包/类
@Test
public void testSerialization() {
MonthDay monthDay = new MonthDay(3,30);
String json = gson.toJson(monthDay);
assertEquals("\"--03-30\"", json);
}
示例15: testDeserialization
import org.joda.time.MonthDay; //导入依赖的package包/类
@Test
public void testDeserialization() {
MonthDay monthDay = gson.fromJson("\"--03-30\"", MonthDay.class);
assertEquals(3, monthDay.getMonthOfYear());
assertEquals(30, monthDay.getDayOfMonth());
}