Date setTime - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Date setTime method.

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;
8
CodeRank
This code example shows how to use the following methods:getTime, setHours, setMinutes, setSeconds, setTime
		} 
    } 
 
    private Date getToday(Calendar calendar) {
        Date today = calendar.getTime();
        today.setTime(today.getTime() / 1000L * 1000L);
        today.setHours(12);
        today.setMinutes(0);
        today.setSeconds(0);
        return today;
    } 
 
    public Date getCoercedDate(Date ifZero, Date ifNotZero) {
        return (calendarDate.getTime() == 0 ? ifZero : ifNotZero);
    } 
 
    public Date getCalendarDate() {
    	return calendarDate;
    } 
 
8
CodeRank
This code example shows how to use the following methods:equals, setTime
	 * Test non-mutable created at date 
	 */ 
	@Test 
	public void nonMutableCreatedAt() { 
		IssueEvent event = new IssueEvent();
		Date date = new Date(1000);
		event.setCreatedAt(date);
		date.setTime(0);
		assertFalse(date.equals(event.getCreatedAt()));
	} 
} 
8
CodeRank
This code example shows how to use the following methods:clone, setHours, setMinutes, setSeconds, setTime
		if (d instanceof java.sql.Date) {
			return d; // java.sql.Date is already truncated to date. And raises
						// an 
						// Exception if we try to set hours, minutes or seconds. 
		} 
		d = (Date) d.clone();
		d.setHours(0);
		d.setMinutes(0);
		d.setSeconds(0);
		d.setTime(((d.getTime() / 1000) * 1000));
		return d;
	} 
 
} 
8
CodeRank
This code example shows how to use the following methods:getTime, getTimezoneOffset, setHours, setMinutes, setSeconds
     * @param time 
     * @return 
     */ 
    public static DateTime unixTimeToGtasksDueDate(long time) {
        if (time < 0) return null;
        Date date = new Date(time);
        date.setHours(0);
        date.setMinutes(0);
        date.setSeconds(0);
        date.setTime(date.getTime() - date.getTimezoneOffset() * 60000);
        DateTime dateTime = new DateTime(date, TimeZone.getTimeZone("UTC"));
        return dateTime;
    } 
 
//    public static DateTime unixTimeToGtasksDueDate(long time) { 
//        if (time == 0) return null; 
//        return new DateTime(time, 0); 
//    } 
 
    //Adjust for google's rounding 
8
CodeRank
This code example shows how to use the following methods:equals, setTime
        assertNotSame(sdf.get2DigitYearStart(), originalDate);
        assertEquals(sdf.get2DigitYearStart(), originalDate);
        originalDate.setTime(0);
        assertFalse(sdf.get2DigitYearStart().equals(originalDate));
        // Test that set2DigitYearStart takes a clone. 
        Date newDate = new Date();
        sdf.set2DigitYearStart(newDate);
        assertNotSame(sdf.get2DigitYearStart(), newDate);
        assertEquals(sdf.get2DigitYearStart(), newDate);
        newDate.setTime(0);
        assertFalse(sdf.get2DigitYearStart().equals(newDate));
    } 
 
    // The RI fails this test because this is an ICU-compatible Android extension. 
    // Necessary for correct localization in various languages (http://b/2633414). 
    public void testStandAloneNames() throws Exception { 
        Locale en = Locale.ENGLISH;
        Locale pl = new Locale("pl");
        Locale ru = new Locale("ru");
 
8
CodeRank
This code example shows how to use the following methods:setTime
	 * Test non-mutable due on date 
	 */ 
	@Test 
	public void setDueOnReferenceMutableObject() { 
		Milestone milestone = new Milestone();
		Date longTimeAgo = new Date(0L);
		milestone.setDueOn(longTimeAgo);
		longTimeAgo.setTime(10000L);
		assertTrue(milestone.getDueOn().getTime() == 0L);
	} 
} 
7
CodeRank
This code example shows how to use the following methods:setTime
	 * Test non-mutable committed at date 
	 */ 
	@Test 
	public void getCreatedAReferenceMutableObject() { 
		GistRevision gistRevision = new GistRevision();
		Date date = new Date(10000);
		gistRevision.setCommittedAt(date);
		gistRevision.getCommittedAt().setTime(0);
		assertTrue(gistRevision.getCommittedAt().getTime() != 0);
		date.setTime(1000);
		assertEquals(10000, gistRevision.getCommittedAt().getTime());
	} 
} 
7
CodeRank
This code example shows how to use the following methods:setTime
  } 
 
  public static Date getTodayWithTime(final String iTime) throws ParseException {
    final SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
    final long today = System.currentTimeMillis();
    final Date rslt = new Date();
    rslt.setTime(today - (today % DAY) + df.parse(iTime).getTime());
    return rslt;
  } 
 
  public static String readFileAsString(final File iFile) throws java.io.IOException {
    return readStreamAsString(new FileInputStream(iFile));
  } 
 
  public static String readStreamAsString(final InputStream iStream) throws java.io.IOException {
    final StringBuffer fileData = new StringBuffer(1000);
    final BufferedReader reader = new BufferedReader(new InputStreamReader(iStream));
    try { 
      final char[] buf = new char[1024];
      int numRead = 0;
7
CodeRank
This code example shows how to use the following methods:getTime, setMinutes, setTime
	} 
 
	/** Initialize the components for the given date field */ 
	public void setDate(Date newDate) {
		if (newDate == null) {
			date = new Date();
			date.setTime(date.getTime() + 1 * 24L * 3600 * 1000);
			date.setMinutes(0);
		} else 
			this.date = new Date(newDate.getTime());
 
		updateDate(); 
		updateTime(); 
	} 
 
	public void onDateSet(DatePicker view, int year, int month, int monthDay) {
		date.setYear(year - 1900);
		date.setMonth(month);
		date.setDate(monthDay);
		updateDate(); 
7
CodeRank
setTime Method Overview
Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.
See Code Examples for other Java 8 Date Methods: