Best code examples for Java 8 Date class (java.util.Date)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Date class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Java 8 Date examples from Open Source projects
This code example shows how to use the following methods:
39:	this.now = new Date(); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: getDate, getDay, getHours, getMinutes, getMonth
24:	json.put("date", date.getDate()); 
25:	json.put("day", date.getDay()); 
26:	json.put("hours", date.getHours()); 
27:	json.put("minutes", date.getMinutes()); 
28:	json.put("month", date.getMonth()); 
29:	json.put("seconds", date.getSeconds()); 
30:	json.put("time", date.getTime()); 
31:	json.put("timezoneOffset", date.getTimezoneOffset()); 
32:	json.put("year", date.getYear()); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods:
36:	final Date date = new Date(); 
37:	BasicDBObject doc = new BasicDBObject( "foo" , date); 
38:	assertTrue( doc.getDate( "foo" ).equals( date ) ); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getTime, setHours, setMinutes, setSeconds, setTime
268:	date.setTime(date.getTime() / 1000L * 1000); 
269:	date.setHours(0); 
270:	date.setMinutes(0); 
271:	date.setSeconds(0); 
272:	return date.getTime(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setDate, setHours, setMinutes, setMonth, setSeconds
33:	Date date = new Date(); 
34:	date.setYear(110); 
35:	date.setMonth(04); 
36:	date.setDate(20); 
37:	date.setHours(10); 
38:	date.setMinutes(25); 
39:	date.setSeconds(30); 
-
43:	String parsedDateString = Util.formatDateToString(date); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: equals, toString
338:	Date d = new Date(); 
-
343:	String serialized = JSON.serialize(d); 
-
347:	assertEquals(d.toString(), d2.toString()); 
348:	assertTrue(d.equals(d2)); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getTime, setHours, setMinutes, setSeconds, setTime
470:	today.setTime(today.getTime() / 1000L * 1000L); 
471:	today.setHours(12); 
472:	today.setMinutes(0); 
473:	today.setSeconds(0); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
24:	this.reference = past.value().equals("") ? new Date() : AlternativeDateFormat.getDefaultFormatter().parse(past.value()); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods:
111:	this.entry.setLastAccessedTime(new Date()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getTime
79:	java.util.Date d = new java.util.Date(); 
80:	ObjectId a = new ObjectId( d ); 
81:	assertEquals( d.getTime() / 1000 , a.getTime() / 1000 ); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setHours, setMinutes, setSeconds
109:	final Date eventDate = new Date(Long.parseLong(getHiddenDate())); 
110:	eventDate.setHours(0); 
111:	eventDate.setMinutes(0); 
112:	eventDate.setSeconds(0); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: equals, setTime
68:	Date date = new Date(1000); 
69:	event.setCreatedAt(date); 
70:	date.setTime(0); 
71:	assertFalse(date.equals(event.getCreatedAt())); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: clone, setHours, setMinutes, setSeconds, setTime
134:	d = (Date) d.clone(); 
135:	d.setHours(0); 
136:	d.setMinutes(0); 
137:	d.setSeconds(0); 
138:	d.setTime(((d.getTime() / 1000) * 1000)); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: toGMTString, toString
64:	assertFalse(tz.inDaylightTime(date)); 
65:	assertEquals("Fri Oct 31 08:00:00 PST 1902", date.toString()); 
66:	assertEquals("31 Oct 1902 16:00:00 GMT", date.toGMTString()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
25:	this.reference = future.value().equals("") ? new Date() : AlternativeDateFormat.getDefaultFormatter().parse(future.value()); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: getTime, getTimezoneOffset, setHours, setMinutes, setSeconds
53:	Date date = new Date(time); 
54:	date.setHours(0); 
55:	date.setMinutes(0); 
56:	date.setSeconds(0); 
57:	date.setTime(date.getTime() - date.getTimezoneOffset() * 60000); 
58:	DateTime dateTime = new DateTime(date, TimeZone.getTimeZone("UTC")); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getTime
55:	return (maxInactiveInterval > 0) ? (System.currentTimeMillis() - this.lastAccessedTime.getTime()) > maxInactiveInterval : false; 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: toString
23:	Date now = new Date(); 
24:	String helloMessage = String.format(hello, now.toString()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
128:	when(this.entry.getLastAccessedTime()).thenReturn(new Date()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getTime
77:	initDate = new Date(); 
-
79:	log.info("RolloutServlet initialized: " + String.valueOf(initDate.getTime())); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getTime
49:	Date date = new Date(); 
-
51:	when(metaData.getCreationTime()).thenReturn(date); 
-
55:	assertEquals(date.getTime(), result); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: toString
24:	Date now = new Date(); 
25:	String helloMessage = String.format(hello, now.toString()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
80:	date = new Date(); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: getTime
92:	Date now = new Date(); 
93:	Long nowLong = (Long) DataTemplateUtil.coerceInput(now, Date.class, Long.class); 
94:	assertEquals(now.getTime(), nowLong.longValue()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getHours, getMinutes, getSeconds, setHours, setMinutes
58:	if (date.getHours() == 23 && date.getMinutes() == 59 && date.getSeconds() == 59) { 
59:	date.setHours(12); 
60:	date.setMinutes(0); 
61:	date.setSeconds(0); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
53:	setStartTime(new Date()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
77:	out.println("<body>Tests passed<br>Time:" + new Date().toString() + "</body>"); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
43:	btn.setText(new Date().toString()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
43:	btn.setText(new Date().toString()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
28:	return new Date(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
121:	message.putStringProperty(propName, "Hello sent at " + new Date()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
20:	Date date = new Date(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
161:	mLog.setText(mLog.getText() + "\n" + mDateFormat.format(new Date()) + ": " + s); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
39:	private final Date date = new Date(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
34:	private static final Date   OBJECT     = new Date(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
202:	long now = new Date().getTime(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
45:	now = new Date(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
35:	private final Date       OBJECT     = new Date(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
74:	_created = new Date(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
48:	date = new Date(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
84:	notice.setText(new Date().toString()); 
Full Snippet Info
8
CodeRank
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: