当前位置: 首页>>代码示例>>Java>>正文


Java GregorianChronology类代码示例

本文整理汇总了Java中org.joda.time.chrono.GregorianChronology的典型用法代码示例。如果您正苦于以下问题:Java GregorianChronology类的具体用法?Java GregorianChronology怎么用?Java GregorianChronology使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GregorianChronology类属于org.joda.time.chrono包,在下文中一共展示了GregorianChronology类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getYearsBetween

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
public static int getYearsBetween(final String date1, final String date2, String format){
    try {
    final DateTimeFormatter fmt =
            DateTimeFormat
                    .forPattern(format)
                    .withChronology(
                            LenientChronology.getInstance(
                                    GregorianChronology.getInstance()));
    return Years.yearsBetween(
            fmt.parseDateTime(date1),
            fmt.parseDateTime(date2)
    ).getYears();
    } catch (Exception ex) {
        ex.printStackTrace();
        return 0;
    }
}
 
开发者ID:Suhas010,项目名称:Artificial-Intelligent-chat-bot-,代码行数:18,代码来源:IntervalUtils.java

示例2: getDaysBetween

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
public static int getDaysBetween(final String date1, final String date2, String format){
    try {
        final DateTimeFormatter fmt =
                DateTimeFormat
                        .forPattern(format)
                        .withChronology(
                                LenientChronology.getInstance(
                                        GregorianChronology.getInstance()));
        return Days.daysBetween(
                fmt.parseDateTime(date1),
                fmt.parseDateTime(date2)
        ).getDays();
    } catch (Exception ex) {
        ex.printStackTrace();
        return 0;
    }
}
 
开发者ID:Suhas010,项目名称:Artificial-Intelligent-chat-bot-,代码行数:18,代码来源:IntervalUtils.java

示例3: getHoursBetween

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
public static int getHoursBetween(final String date1, final String date2, String format){
    try {
    final DateTimeFormatter fmt =
            DateTimeFormat
                    .forPattern(format)
                    .withChronology(
                            LenientChronology.getInstance(
                                    GregorianChronology.getInstance()));
    return Hours.hoursBetween(
            fmt.parseDateTime(date1),
            fmt.parseDateTime(date2)
    ).getHours();
    } catch (Exception ex) {
        ex.printStackTrace();
        return 0;
    }
}
 
开发者ID:Suhas010,项目名称:Artificial-Intelligent-chat-bot-,代码行数:18,代码来源:IntervalUtils.java

示例4: getMonthsBetween

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
public static int getMonthsBetween(final String date1, final String date2, String format){
    try {
    final DateTimeFormatter fmt =
            DateTimeFormat
                    .forPattern(format)
                    .withChronology(
                            LenientChronology.getInstance(
                                    GregorianChronology.getInstance()));
    return Months.monthsBetween(
            fmt.parseDateTime(date1),
            fmt.parseDateTime(date2)
    ).getMonths();
    } catch (Exception ex) {
        ex.printStackTrace();
        return 0;
    }
}
 
开发者ID:Suhas010,项目名称:Artificial-Intelligent-chat-bot-,代码行数:18,代码来源:IntervalUtils.java

示例5: reformatFerretToISO

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
private String reformatFerretToISO(String in) {
    Chronology chrono = GregorianChronology.getInstance(DateTimeZone.UTC);
    DateTimeFormatter iso = ISODateTimeFormat.dateTime().withChronology(chrono).withZone(DateTimeZone.UTC);;
    DateTimeFormatter sFerretForm = DateTimeFormat.forPattern("dd-MMM-yyyy").withChronology(chrono).withZone(DateTimeZone.UTC);
    DateTimeFormatter lFerretForm = DateTimeFormat.forPattern("dd-MMM-yyyy HH:mm").withChronology(chrono).withZone(DateTimeZone.UTC);

    DateTime td;
    try {
        td = lFerretForm.parseDateTime(in).withZone(DateTimeZone.UTC).withChronology(chrono);
    } catch (Exception e) {
        try {
            td = sFerretForm.parseDateTime(in).withZone(DateTimeZone.UTC).withChronology(chrono);
        } catch (Exception e2) {
            return null;
        }
    }
    if ( td != null ) {
        return iso.print(td.getMillis());
    } else {
        return null;
    }
}
 
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:23,代码来源:RPCServiceImpl.java

示例6: getChronology

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
/**
 * Gets the chronology, which is the GJChronology if a GregorianCalendar is used,
 * BuddhistChronology if a BuddhistCalendar is used or ISOChronology otherwise.
 * The time zone specified is used in preference to that on the calendar.
 * 
 * @param object  the Calendar to convert, must not be null
 * @param zone  the specified zone to use, null means default zone
 * @return the chronology, never null
 * @throws NullPointerException if the object is null
 * @throws ClassCastException if the object is an invalid type
 */
public Chronology getChronology(Object object, DateTimeZone zone) {
    if (object.getClass().getName().endsWith(".BuddhistCalendar")) {
        return BuddhistChronology.getInstance(zone);
    } else if (object instanceof GregorianCalendar) {
        GregorianCalendar gc = (GregorianCalendar) object;
        long cutover = gc.getGregorianChange().getTime();
        if (cutover == Long.MIN_VALUE) {
            return GregorianChronology.getInstance(zone);
        } else if (cutover == Long.MAX_VALUE) {
            return JulianChronology.getInstance(zone);
        } else {
            return GJChronology.getInstance(zone, cutover, 4);
        }
    } else {
        return ISOChronology.getInstance(zone);
    }
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:29,代码来源:CalendarConverter.java

示例7: testBug2182444_ausNSW

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
public void testBug2182444_ausNSW() {
    Chronology chronAusNSW = GregorianChronology.getInstance(DateTimeZone.forID("Australia/NSW"));
    Chronology chronUTC = GregorianChronology.getInstance(DateTimeZone.UTC);
    DateTime australiaNSWStandardInUTC = new DateTime(2008, 4, 5, 16, 0, 0, 0, chronUTC);
    DateTime australiaNSWDaylightInUTC = new DateTime(2008, 4, 5, 15, 0, 0, 0, chronUTC);
    assertTrue("Should be standard time", chronAusNSW.getZone().isStandardOffset(australiaNSWStandardInUTC.getMillis()));
    assertFalse("Should be daylight time", chronAusNSW.getZone().isStandardOffset(australiaNSWDaylightInUTC.getMillis()));
    
    DateTime australiaNSWStandardInAustraliaNSW = australiaNSWStandardInUTC.toDateTime(chronAusNSW);
    DateTime australiaNSWDaylightInAusraliaNSW = australiaNSWDaylightInUTC.toDateTime(chronAusNSW);
    assertEquals(2, australiaNSWStandardInAustraliaNSW.getHourOfDay());
    assertEquals(australiaNSWStandardInAustraliaNSW.getHourOfDay(), australiaNSWDaylightInAusraliaNSW.getHourOfDay());
    assertTrue(australiaNSWStandardInAustraliaNSW.getMillis() != australiaNSWDaylightInAusraliaNSW.getMillis());
    assertEquals(australiaNSWStandardInAustraliaNSW, australiaNSWStandardInAustraliaNSW.withHourOfDay(2));
    assertEquals(australiaNSWStandardInAustraliaNSW.getMillis() + 3, australiaNSWStandardInAustraliaNSW.withMillisOfSecond(3).getMillis());
    assertEquals(australiaNSWDaylightInAusraliaNSW, australiaNSWDaylightInAusraliaNSW.withHourOfDay(2));
    assertEquals(australiaNSWDaylightInAusraliaNSW.getMillis() + 3, australiaNSWDaylightInAusraliaNSW.withMillisOfSecond(3).getMillis());
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:TestDateTimeZoneCutover.java

示例8: testIsEqual_MD

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
public void testIsEqual_MD() {
    MonthDay test1 = new MonthDay(6, 6);
    MonthDay test1a = new MonthDay(6, 6);
    assertEquals(true, test1.isEqual(test1a));
    assertEquals(true, test1a.isEqual(test1));
    assertEquals(true, test1.isEqual(test1));
    assertEquals(true, test1a.isEqual(test1a));
    
    MonthDay test2 = new MonthDay(6, 7);
    assertEquals(false, test1.isEqual(test2));
    assertEquals(false, test2.isEqual(test1));
    
    MonthDay test3 = new MonthDay(6, 7, GregorianChronology.getInstanceUTC());
    assertEquals(false, test1.isEqual(test3));
    assertEquals(false, test3.isEqual(test1));
    assertEquals(true, test3.isEqual(test2));
    
    try {
        new MonthDay(6, 7).isEqual(null);
        fail();
    } catch (IllegalArgumentException ex) {}
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:TestMonthDay_Basics.java

示例9: testIsBefore_MD

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
public void testIsBefore_MD() {
    MonthDay test1 = new MonthDay(6, 6);
    MonthDay test1a = new MonthDay(6, 6);
    assertEquals(false, test1.isBefore(test1a));
    assertEquals(false, test1a.isBefore(test1));
    assertEquals(false, test1.isBefore(test1));
    assertEquals(false, test1a.isBefore(test1a));
    
    MonthDay test2 = new MonthDay(6, 7);
    assertEquals(true, test1.isBefore(test2));
    assertEquals(false, test2.isBefore(test1));
    
    MonthDay test3 = new MonthDay(6, 7, GregorianChronology.getInstanceUTC());
    assertEquals(true, test1.isBefore(test3));
    assertEquals(false, test3.isBefore(test1));
    assertEquals(false, test3.isBefore(test2));
    
    try {
        new MonthDay(6, 7).isBefore(null);
        fail();
    } catch (IllegalArgumentException ex) {}
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:TestMonthDay_Basics.java

示例10: testIsEqual_YM

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
public void testIsEqual_YM() {
    YearMonth test1 = new YearMonth(2005, 6);
    YearMonth test1a = new YearMonth(2005, 6);
    assertEquals(true, test1.isEqual(test1a));
    assertEquals(true, test1a.isEqual(test1));
    assertEquals(true, test1.isEqual(test1));
    assertEquals(true, test1a.isEqual(test1a));
    
    YearMonth test2 = new YearMonth(2005, 7);
    assertEquals(false, test1.isEqual(test2));
    assertEquals(false, test2.isEqual(test1));
    
    YearMonth test3 = new YearMonth(2005, 7, GregorianChronology.getInstanceUTC());
    assertEquals(false, test1.isEqual(test3));
    assertEquals(false, test3.isEqual(test1));
    assertEquals(true, test3.isEqual(test2));
    
    try {
        new YearMonth(2005, 7).isEqual(null);
        fail();
    } catch (IllegalArgumentException ex) {}
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:TestYearMonth_Basics.java

示例11: testIsEqual_RI

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
public void testIsEqual_RI() {
    Instant test1 = new Instant(TEST_TIME1);
    Instant test1a = new Instant(TEST_TIME1);
    assertEquals(true, test1.isEqual(test1a));
    assertEquals(true, test1a.isEqual(test1));
    assertEquals(true, test1.isEqual(test1));
    assertEquals(true, test1a.isEqual(test1a));
    
    Instant test2 = new Instant(TEST_TIME2);
    assertEquals(false, test1.isEqual(test2));
    assertEquals(false, test2.isEqual(test1));
    
    DateTime test3 = new DateTime(TEST_TIME2, GregorianChronology.getInstance(PARIS));
    assertEquals(false, test1.isEqual(test3));
    assertEquals(false, test3.isEqual(test1));
    assertEquals(true, test3.isEqual(test2));
    
    assertEquals(false, test2.isEqual(new MockInstant()));
    assertEquals(true, test1.isEqual(new MockInstant()));
    
    assertEquals(false, new Instant(TEST_TIME_NOW + 1).isEqual(null));
    assertEquals(true, new Instant(TEST_TIME_NOW).isEqual(null));
    assertEquals(false, new Instant(TEST_TIME_NOW - 1).isEqual(null));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:TestInstant_Basics.java

示例12: testIsBefore_RI

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
public void testIsBefore_RI() {
    Instant test1 = new Instant(TEST_TIME1);
    Instant test1a = new Instant(TEST_TIME1);
    assertEquals(false, test1.isBefore(test1a));
    assertEquals(false, test1a.isBefore(test1));
    assertEquals(false, test1.isBefore(test1));
    assertEquals(false, test1a.isBefore(test1a));
    
    Instant test2 = new Instant(TEST_TIME2);
    assertEquals(true, test1.isBefore(test2));
    assertEquals(false, test2.isBefore(test1));
    
    DateTime test3 = new DateTime(TEST_TIME2, GregorianChronology.getInstance(PARIS));
    assertEquals(true, test1.isBefore(test3));
    assertEquals(false, test3.isBefore(test1));
    assertEquals(false, test3.isBefore(test2));
    
    assertEquals(false, test2.isBefore(new MockInstant()));
    assertEquals(false, test1.isBefore(new MockInstant()));
    
    assertEquals(false, new Instant(TEST_TIME_NOW + 1).isBefore(null));
    assertEquals(false, new Instant(TEST_TIME_NOW).isBefore(null));
    assertEquals(true, new Instant(TEST_TIME_NOW - 1).isBefore(null));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:TestInstant_Basics.java

示例13: testIsAfter_TOD

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
public void testIsAfter_TOD() {
    TimeOfDay test1 = new TimeOfDay(10, 20, 30, 40);
    TimeOfDay test1a = new TimeOfDay(10, 20, 30, 40);
    assertEquals(false, test1.isAfter(test1a));
    assertEquals(false, test1a.isAfter(test1));
    assertEquals(false, test1.isAfter(test1));
    assertEquals(false, test1a.isAfter(test1a));
    
    TimeOfDay test2 = new TimeOfDay(10, 20, 35, 40);
    assertEquals(false, test1.isAfter(test2));
    assertEquals(true, test2.isAfter(test1));
    
    TimeOfDay test3 = new TimeOfDay(10, 20, 35, 40, GregorianChronology.getInstanceUTC());
    assertEquals(false, test1.isAfter(test3));
    assertEquals(true, test3.isAfter(test1));
    assertEquals(false, test3.isAfter(test2));
    
    try {
        new TimeOfDay(10, 20, 35, 40).isAfter(null);
        fail();
    } catch (IllegalArgumentException ex) {}
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:TestTimeOfDay_Basics.java

示例14: difference_between_two_dates_joda_duration

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
@Test
public void difference_between_two_dates_joda_duration () {

	DateTime sinceGraduation = new DateTime(1984, 6, 4, 0, 0, GregorianChronology.getInstance());
	DateTime currentDate = new DateTime(); //current date

	Duration duration = new Duration(sinceGraduation, currentDate);

	logger.info(duration.getStandardDays());
	logger.info(duration.getStandardHours());
	logger.info(duration.getStandardMinutes());
	logger.info(duration.getStandardSeconds());
	
	assertTrue(duration.getStandardDays() >= 10697);
	assertTrue(duration.getStandardHours() >= 256747);
	assertTrue(duration.getStandardMinutes() >= 15404876);
	assertTrue(duration.getStandardSeconds() >= 924292577);
}
 
开发者ID:wq19880601,项目名称:java-util-examples,代码行数:19,代码来源:CalculateDateTimeDifference.java

示例15: difference_between_two_dates_joda

import org.joda.time.chrono.GregorianChronology; //导入依赖的package包/类
@Test
public void difference_between_two_dates_joda () {
	
	DateTime sinceGraduation = new DateTime(1984, 6, 4, 0, 0, GregorianChronology.getInstance());
	DateTime currentDate = new DateTime(); //current date

	Days diffInDays = Days.daysBetween(sinceGraduation, currentDate);
	Hours diffInHours = Hours.hoursBetween(sinceGraduation, currentDate);
	Minutes diffInMinutes = Minutes.minutesBetween(sinceGraduation, currentDate);
	Seconds seconds = Seconds.secondsBetween(sinceGraduation, currentDate);
	
	logger.info(diffInDays.getDays());
	logger.info(diffInHours.getHours());
	logger.info(diffInMinutes.getMinutes());
	logger.info(seconds.getSeconds());
	
	assertTrue(diffInDays.getDays() >= 10697);
	assertTrue(diffInHours.getHours() >= 256747);
	assertTrue(diffInMinutes.getMinutes() >= 15404876);
	assertTrue(seconds.getSeconds() >= 924292577);

}
 
开发者ID:wq19880601,项目名称:java-util-examples,代码行数:23,代码来源:CalculateDateTimeDifference.java


注:本文中的org.joda.time.chrono.GregorianChronology类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。