Java 8 Date - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Date class.

This code example shows how to use the following methods:toString
        StaticHibernateUtil.flushSession(); 
    } 
 
    @Test 
    public void testBuildDateUI() { 
        Date date = new Date(System.currentTimeMillis());
       Assert.assertTrue(new SavingsOverDueDepositsTag().buildDateUI(new Locale("en", "GB"), date).toString().contains(
                DateUtils.getUserLocaleDate(new Locale("en", "GB"), date.toString())));
 
    } 
 
    @Test 
    public void testBuildAmountUI() { 
       Assert.assertTrue(new SavingsOverDueDepositsTag().buildAmountUI(new Money(getCurrency(), "1000")).toString().contains("1,000"));
    } 
 
    @Test 
    public void testBuildDepositDueUIRow() { 
        Date date = new Date(System.currentTimeMillis());
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getDate, getMonth, getYear
    public void testFromString() 
    { 
        Assert.assertNull(accessor.fromString(Date.class, null));
         
        long l = System.currentTimeMillis();        
        Date d = new Date(l);        
        Date d2 = accessor.fromString(Date.class, "" + l);
        Assert.assertEquals(d, d2);
         
        Assert.assertEquals(d.getYear(), accessor.fromString(Date.class, d2.toString()).getYear());
        Assert.assertEquals(d.getMonth(), accessor.fromString(Date.class, d2.toString()).getMonth());
        Assert.assertEquals(d.getDate(), accessor.fromString(Date.class, d2.toString()).getDate());        
    } 
 
    /** 
     * Test method for {@link com.impetus.kundera.property.accessor.SQLDateAccessor#getCopy(java.lang.Object)}. 
     */ 
    @Test
    public void testGetCopy() 
    { 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHours, getMinutes, getSeconds, setHours, setMinutes
    Date sqlDate = new Date(2000 - 1900, 1 - 1, 1);
    assertEquals("2000-01-01", sqlDate.toString());
  } 
   
  public void testUnimplementedFunctions() { 
    Date d = new Date(0);
 
    try { 
      d.getHours();
      fail("Should have thrown IllegalArgumentException"); 
    } catch (IllegalArgumentException e) {
      // Expected behavior 
    } 
 
    try { 
      d.getMinutes();
      fail("Should have thrown IllegalArgumentException"); 
    } catch (IllegalArgumentException e) {
      // Expected behavior 
    } 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getDate, getMonth, getYear
     * @param date Date to convert to ordinal, since 01/01/01 
     * @return The ordinal representing the date 
     */ 
    public static int dateToOrdinal(Date date) {
        // BigDate.toOrdinal returns the ordinal since 1970, so we add up the days from 01/01/01 to 1970 
        return BigDate.toOrdinal(date.getYear() + 1900, date.getMonth() + 1, date.getDate()) + DAYS_BEFORE_1970;
    } 
 
 
    /** 
     * Return the date corresponding to the proleptic Gregorian ordinal, where January 1 of year 1 has ordinal 1. 
     * @param ordinal representing the days since 01/01/01 
     * @return Date converted from the ordinal 
     */ 
    public static Date ordinalToDate(int ordinal) {
        return new Date((ordinal - DAYS_BEFORE_1970) * MILLIS_IN_A_DAY);
    } 
 
 
    /** 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:equals, getDate, getMonth, getYear
   * @param date  the SQL date to convert, not null 
   * @return the date, not null 
   */ 
  @SuppressWarnings("deprecation") 
  public static LocalDate fromSqlDate(Date date) {
    ArgumentChecker.notNull(date, "date");
    return LocalDate.of(date.getYear() + 1900, date.getMonth() + 1, date.getDate());
  } 
 
  /** 
   * Creates a {@code LocalDate} from a SQL date. 
   *  
   * @param date  the SQL date to convert, not null 
   * @return the date, null if far future 
   */ 
  public static LocalDate fromSqlDateNullFarFuture(Date date) {
    if (date.equals(MAX_SQL_DATE)) {
      return null; 
    } 
    return fromSqlDate(date);

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setTime, toString
    outV.setVal(i, bytes, 0, length);
  } 
 
  @Override 
  protected void func(BytesColumnVector outV, long[] vector, int i) {
    dt.setTime(DateWritable.daysToMillis((int) vector[i]));
    byte[] temp = dt.toString().getBytes();
    assign(outV, i, temp, temp.length);
  } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toString
        StaticHibernateUtil.flushSession(); 
    } 
 
    @Test
    public void testBuildDateUI() { 
        Date date = new Date(System.currentTimeMillis());
       Assert.assertTrue(new SavingsOverDueDepositsTag().buildDateUI(new Locale("en", "GB"), date).toString().contains(
                DateUtils.getUserLocaleDate(new Locale("en", "GB"), date.toString())));
 
    } 
 
    @Test
    public void testBuildAmountUI() { 
       Assert.assertTrue(new SavingsOverDueDepositsTag().buildAmountUI(new Money(getCurrency(), "1000")).toString().contains("1,000"));
    } 
 
    @Test
    public void testBuildDepositDueUIRow() { 
        Date date = new Date(System.currentTimeMillis());
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHours, getMinutes, getSeconds, setHours, setMinutes
    Date sqlDate = new Date(2000 - 1900, 1 - 1, 1);
    assertEquals("2000-01-01", sqlDate.toString());
  } 
   
  public void testUnimplementedFunctions() { 
    Date d = new Date(0);
 
    try { 
      d.getHours();
      fail("Should have thrown IllegalArgumentException"); 
    } catch (IllegalArgumentException e) {
      // Expected behavior 
    } 
 
    try { 
      d.getMinutes();
      fail("Should have thrown IllegalArgumentException"); 
    } catch (IllegalArgumentException e) {
      // Expected behavior 
    } 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getTime, equals
        rs.close();
    } 
 
    @Test 
    public void date2() throws SQLException { 
        Date d1 = new Date(1092941466000L);
        stat.execute("create table t (c1);");
        PreparedStatement prep = conn.prepareStatement("insert into t values (datetime(?/1000, 'unixepoch'));");
        prep.setDate(1, d1);
        prep.executeUpdate();
 
        ResultSet rs = stat.executeQuery("select strftime('%s', c1) * 1000 from t;");
        assertTrue(rs.next());
        assertEquals(rs.getLong(1), d1.getTime());
        assertTrue(rs.getDate(1).equals(d1));
    } 
 
    @Test 
    public void changeSchema() throws SQLException { 
        stat.execute("create table t (c1);");
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toString, getTime
        Date twoDaysAgo = addFeatureWithTimeTwoDaysAgo(fid++);
        this.addFeature(fid++, twoDaysAgo,Double.valueOf(0d));
 
        java.util.Date d = wms.getDefaultTime(timeWithStartEnd);
        assertTrue("Default time is null", d != null);
        assertTrue("Default time should be the closest one", d.getTime() == twoDaysAgo.getTime());
         
        // Add some features with timestamps in the future: 
        Date dayAfterTomorrow = addFeatureWithTimeDayAfterTomorrow(fid++);
        addFeatureWithTimeOneYearFromNow(fid++);
                
        d = wms.getDefaultTime(timeWithStartEnd);
        assertTrue("Default time is null", d != null);
        assertTrue("Default time should be the closest one", d.getTime() == dayAfterTomorrow.getTime());
         
        Date todayMidnight = addFeatureWithTimeTodayMidnight(fid++);
      
        d = wms.getDefaultTime(timeWithStartEnd);
        assertTrue("Default time is null", d != null);
        assertTrue("Default time should be the closest one", d.getTime() == todayMidnight

6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 Date Questions & Answers:

See Code Examples for Java 8 Date Methods: