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:
 
    private Date now;
 
    public TimestampedTable () { 
        super(); 
        this.now = new Date();
    } 
 
    @Override 
    public Table startHeaders() { 
        inHeaders = true; 
        currentCells = new ArrayList<Cell>();
         
        final Map<String, String> epochAttr = Maps.newHashMap();
        epochAttr.put("desc", "seconds since 1970-01-01 00:00:00 when request executed");
         
        final Map<String, String> hmsAttr = Maps.newHashMap();
        hmsAttr.put("desc", "human time when request executed");
         
        currentCells.add(new Cell("epoch", epochAttr));
Full Snippet Info
9
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getDate, getDay, getHours, getMinutes, getMonth
    	} 
    	 
        Date date = (Date) object;
        
        JSONObject json = new JSONObject();
        json.put("date", date.getDate());
        json.put("day", date.getDay());
        json.put("hours", date.getHours());
        json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());
        json.put("year", date.getYear());
 
        serializer.write(json);
    } 
} 
Full Snippet Info
9
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods:
 
public class BasicDBObjectTest extends TestCase {
 
    @Test 
    public void testGetDate() { 
        final Date date = new Date();
        BasicDBObject doc = new BasicDBObject( "foo" , date);
        assertTrue( doc.getDate( "foo" ).equals( date ) );
    } 
 
    @Test 
    public void testGetDateWithDefault() { 
        final Date date = new Date();
        BasicDBObject doc = new BasicDBObject( "foo" , date);
        assertTrue( doc.getDate( "foo", new Date() ).equals( date ) );
        assertTrue( doc.getDate( "bar", date ).equals( date ) );
    } 
 
    @Test 
    public void testGetObjectId() { 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getTime, setHours, setMinutes, setSeconds, setTime
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTimeInMillis();
    } 
 
    private static long clearTime(Date date) {
        date.setTime(date.getTime() / 1000L * 1000);
        date.setHours(0);
        date.setMinutes(0);
        date.setSeconds(0);
        return date.getTime();
    } 
 
    public static boolean isoStringHasTime(String iso8601String) {
        return iso8601String.length() > 10;
    } 
 
    public static long parseIso8601(String iso8601String) throws ParseException {
        if (iso8601String == null)
            return 0; 
        String formatString;
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: setDate, setHours, setMinutes, setMonth, setSeconds
    assertEquals(06, date.getMinutes());
    assertEquals(18, date.getSeconds());
  }   
   
  public void testParseDateToString() { 
    Date date = new Date();
    date.setYear(110);
    date.setMonth(04);
    date.setDate(20);
    date.setHours(10);
    date.setMinutes(25);
    date.setSeconds(30);
     
    String expectedDateString = "2010-05-20T10:25:30+03:00"; // +xx:xx depends on timezone
     
    String parsedDateString = Util.formatDateToString(date); 
     
    Log.d("UtilTest", "************");
    Log.d("UtilTest", "expectedDateString" + expectedDateString);
    Log.d("UtilTest", "parsedDateString" + parsedDateString);
    Log.d("UtilTest", "************");
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 Date Questions & Answers:

Other Java 8 Date Examples

266:			// Create a media file name
267:			String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
268:					Locale.getDefault()).format(new Date());
269:			File mediaFile;
270:			if (type == MEDIA_TYPE_IMAGE) {

Read More

373:			SimpleDateFormat dateFormat = new SimpleDateFormat(
374:					"yyyy-MM-dd HH:mm:ss", Locale.getDefault());
375:			Date date = new Date();
376:			return dateFormat.format(date);
377:		}
-
373:			SimpleDateFormat dateFormat = new SimpleDateFormat(
374:					"yyyy-MM-dd HH:mm:ss", Locale.getDefault());
375:			Date date = new Date();
376:			return dateFormat.format(date);
377:		}

Read More

See Code Examples for Java 8 Date Methods: