Java Code Examples for java.util.Date#setSeconds()

The following examples show how to use java.util.Date#setSeconds() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: doov   File: DateTypeAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public Object fromString(FieldInfo info, String value) {
    int year = Integer.parseInt(value.substring(0, 4));
    int month = Integer.parseInt(value.substring(4, 6));
    int day = Integer.parseInt(value.substring(6, 8));

    Date date = new Date();
    date.setDate(day);
    date.setMonth(month - 1);
    date.setYear(year - 1900);
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    return date;
}
 
Example 2
@Test
public void testDurationAndCalendar3() {
    try {
        Calendar cal = new GregorianCalendar();
        cal.set(Calendar.SECOND, 59);
        DatatypeFactory.newInstance().newDuration(10000).addTo(cal);
        AssertJUnit.assertTrue("sec will be 9", cal.get(Calendar.SECOND) == 9);

        Date date = new Date();
        date.setSeconds(59);
        DatatypeFactory.newInstance().newDuration(10000).addTo(date);
        AssertJUnit.assertTrue("sec will be 9", date.getSeconds() == 9);
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 3
Source Project: Android-Allocine-Api   File: Horaires.java    License: Apache License 2.0 6 votes vote down vote up
public boolean isMoreThanToday() {
        try {
            String dateFormatted = getDate();

            Date now = new Date();
            now.setHours(0);
            now.setSeconds(0);
            now.setMinutes(0);

            SimpleDateFormat formater = new SimpleDateFormat("E dd MMMMM yyyy", Locale.FRANCE);
            Date date = formater.parse(dateFormatted);

            date.setHours(13);

            return date.equals(now) || date.after(now);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
}
 
Example 4
Source Project: JavaRush   File: Solution.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
private static boolean isDateOdd(String date) {
  boolean bool;
  Date date1 = new Date(date);
  Date ms = new Date(date);
  ms.setHours(0);
  ms.setMinutes(0);
  ms.setSeconds(0);
  ms.setMonth(0);
  ms.setDate(1);
  long num = date1.getTime() - ms.getTime();
  long dayMs = 24 * 60 * 60 * 1000;
  int day = (int) (num / dayMs);
  bool = day % 2 == 0;
  return bool;
}
 
Example 5
Source Project: viritin   File: MDateField.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void setValue(Date newValue, boolean repaintIsNotNeeded) throws ReadOnlyException {
    if (settingInitialValue && getResolution().ordinal() > Resolution.HOUR.ordinal()) {
        if (getInitialTimeMode() == InitialTimeMode.START_OF_DAY) {
            newValue.setHours(0);
            newValue.setMinutes(0);
            newValue.setSeconds(0);
            newValue.setTime(
                    newValue.getTime() - newValue.getTime() % 1000l);
        } else if (getInitialTimeMode() == InitialTimeMode.END_OF_DAY) {
            newValue.setHours(23);
            newValue.setMinutes(59);
            newValue.setSeconds(59);
            newValue.setTime(
                    newValue.getTime() - newValue.getTime() % 1000l + 999l);
        }
    }
    super.setValue(newValue, repaintIsNotNeeded);
}
 
Example 6
Source Project: UltimateAndroid   File: MeetingDAO.java    License: Apache License 2.0 6 votes vote down vote up
public Meeting findByTeamAndDate(Team team, Date date) {
    Cursor cursor = null;
    Meeting meeting = null;

    try {
        long startTime = date.getTime();
        Date endDate = new Date(date.getTime());
        endDate.setSeconds(endDate.getSeconds() + 1);
        long endTime = endDate.getTime();

        SQLiteDatabase db = getReadableDatabase();
        cursor = db.query(MEETINGS_TABLE_NAME, MEETINGS_ALL_COLUMS,
                MEETINGS_TEAM_NAME + " = ? and " + MEETINGS_MEETING_TIME + " >= ? and " + MEETINGS_MEETING_TIME + " < ?",
                new String[] {team.getName(), Long.toString(startTime), Long.toString(endTime)},
                null, null, null);
        if (cursor.getCount() == 1) {
            if (cursor.moveToFirst()) {
                meeting = createMeetingFromCursorData(cursor);
            }
        }
    } finally {
        closeCursor(cursor);
    }

    return meeting;
}
 
Example 7
Source Project: UltimateAndroid   File: MeetingDAO.java    License: Apache License 2.0 6 votes vote down vote up
public Meeting findByTeamAndDate(Team team, Date date) {
    Cursor cursor = null;
    Meeting meeting = null;

    try {
        long startTime = date.getTime();
        Date endDate = new Date(date.getTime());
        endDate.setSeconds(endDate.getSeconds() + 1);
        long endTime = endDate.getTime();

        SQLiteDatabase db = getReadableDatabase();
        cursor = db.query(MEETINGS_TABLE_NAME, MEETINGS_ALL_COLUMS,
                MEETINGS_TEAM_NAME + " = ? and " + MEETINGS_MEETING_TIME + " >= ? and " + MEETINGS_MEETING_TIME + " < ?",
                new String[] {team.getName(), Long.toString(startTime), Long.toString(endTime)},
                null, null, null);
        if (cursor.getCount() == 1) {
            if (cursor.moveToFirst()) {
                meeting = createMeetingFromCursorData(cursor);
            }
        }
    } finally {
        closeCursor(cursor);
    }

    return meeting;
}
 
Example 8
Source Project: front50   File: GcsStorageService.java    License: Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
public void scheduleWriteLastModified(String daoTypeName) {
  Date when = new Date();
  when.setSeconds(when.getSeconds() + 2);
  GcsStorageService service = this;
  Runnable task =
      new Runnable() {
        public void run() {
          // Release the scheduled update lock, and perform the actual update
          scheduledUpdateLock(daoTypeName).set(false);
          log.info("RUNNING {}", daoTypeName);
          service.writeLastModified(daoTypeName);
        }
      };
  if (scheduledUpdateLock(daoTypeName).compareAndSet(false, true)) {
    log.info("Scheduling deferred update {} timestamp.", daoTypeName);
    taskScheduler.schedule(task, when);
  }
}
 
Example 9
Source Project: flink-learning   File: DateUtilTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTimeAtEndOfNow() {
    Date date = new Date();
    date.setHours(23);
    date.setMinutes(59);
    date.setSeconds(59);
    String data = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
    Assert.assertEquals(data, DateUtil.withTimeAtEndOfNow());
}
 
Example 10
Source Project: flink-learning   File: DateUtilTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTimeAtStartOfNow() {
    Date date = new Date();
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    String data = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
    Assert.assertEquals(data, DateUtil.withTimeAtStartOfNow());
}
 
Example 11
Source Project: flink-learning   File: DateUtilTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTimeAtEndOfNow() {
    Date date = new Date();
    date.setHours(23);
    date.setMinutes(59);
    date.setSeconds(59);
    String data = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
    Assert.assertEquals(data, DateUtil.withTimeAtEndOfNow());
}
 
Example 12
@SuppressWarnings("deprecation")
public static Date dateAddSeconds(int year, int month, int day, long second) {
    Date dt = new Date();
    dt.setYear(year - 1900);
    dt.setMonth(month - 1);
    dt.setDate(day);
    dt.setHours(0);
    dt.setMinutes(0);
    dt.setSeconds(0);
    Calendar rightNow = Calendar.getInstance();
    rightNow.setTime(dt);
    rightNow.add(Calendar.SECOND, (int) second);
    Date dt1 = rightNow.getTime();
    return dt1;
}
 
Example 13
@SuppressWarnings("deprecation")
public static CharSequence getRelativeDateTimeString (
        Context c, long time, long minResolution, long transitionResolution, int flags
        ){
    
    CharSequence dateString = "";
    
    // in Future
    if (time > System.currentTimeMillis()){
        return DisplayUtils.unixTimeToHumanReadable(time);
    } 
    // < 60 seconds -> seconds ago
    else if ((System.currentTimeMillis() - time) < 60 * 1000) {
        return c.getString(R.string.file_list_seconds_ago);
    } else {
        // Workaround 2.x bug (see https://github.com/owncloud/android/issues/716)
        if (    Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB && 
                (System.currentTimeMillis() - time) > 24 * 60 * 60 * 1000   ) {
            Date date = new Date(time);
            date.setHours(0);
            date.setMinutes(0);
            date.setSeconds(0);
            dateString = DateUtils.getRelativeDateTimeString(
                    c, date.getTime(), minResolution, transitionResolution, flags
            );
        } else {
            dateString = DateUtils.getRelativeDateTimeString(c, time, minResolution, transitionResolution, flags);
        }
    }
    
    return dateString.toString().split(",")[0];
}
 
Example 14
Source Project: datacollector   File: TimeNowEL.java    License: Apache License 2.0 5 votes vote down vote up
@ElFunction(prefix = TIME_CONTEXT_VAR, name = "trimTime", description = "Set time portion of datetime expression to 00:00:00")
@SuppressWarnings("deprecation")
public static Date trimTime(@ElParam("datetime") Date in) {
  if(in == null) {
    return null;
  }

  Date ret = new Date(in.getTime());
  ret.setHours(0);
  ret.setMinutes(0);
  ret.setSeconds(0);
  return ret;
}
 
Example 15
Source Project: j2objc   File: DateTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * java.util.Date#setSeconds(int)
 */
public void test_setSecondsI() {
    // Test for method void java.util.Date.setSeconds(int)
    Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
            .getTime();
    d.setSeconds(13);
    assertEquals("Set incorrect seconds", 13, d.getSeconds());
}
 
Example 16
protected Date firstIntervalDate(DateIntervalType intervalType, Date minDate, ColumnGroup columnGroup) {
    Date intervalMinDate = new Date(minDate.getTime());
    if (YEAR.equals(intervalType)) {
        intervalMinDate.setMonth(0);
        intervalMinDate.setDate(1);
        intervalMinDate.setHours(0);
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (QUARTER.equals(intervalType)) {
        int currentMonth = intervalMinDate.getMonth();
        int firstMonthYear = columnGroup.getFirstMonthOfYear().getIndex();
        int rest = Quarter.getPositionInQuarter(firstMonthYear, currentMonth + 1);
        intervalMinDate.setMonth(currentMonth - rest);
        intervalMinDate.setDate(1);
        intervalMinDate.setHours(0);
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (MONTH.equals(intervalType)) {
        intervalMinDate.setDate(1);
        intervalMinDate.setHours(0);
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (DAY.equals(intervalType) || DAY_OF_WEEK.equals(intervalType) || WEEK.equals(intervalType)) {
        intervalMinDate.setHours(0);
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (HOUR.equals(intervalType)) {
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (MINUTE.equals(intervalType)) {
        intervalMinDate.setSeconds(0);
    }
    return intervalMinDate;
}
 
Example 17
Source Project: es   File: CalendarService.java    License: Apache License 2.0 5 votes vote down vote up
public Long countRecentlyCalendar(Long userId, Integer interval) {
    Date nowDate = new Date();
    Date nowTime = new Time(nowDate.getHours(), nowDate.getMinutes(), nowDate.getSeconds());
    nowDate.setHours(0);
    nowDate.setMinutes(0);
    nowDate.setSeconds(0);

    return getCalendarRepository().countRecentlyCalendar(userId, nowDate, nowTime, interval);
}
 
Example 18
@Override
public ValidateCondition getConditon() {
	ValidateCondition condition = new ValidateCondition();
			
		
		Date date = new Date();
		Date date2 = util.Tool.addDate(date, 1);
		Date date3 = new Date();
		date3.setHours(15);
		date3.setMinutes(0);
		date3.setSeconds(0);
		Date date4 = new Date();
		date4.setHours(17);
		date4.setMinutes(0);
		date4.setSeconds(0);
		
		condition.setArrivalDate(date);
		condition.setDepartureDate(date2);
		condition.setHotelId("10101129");
		condition.setRoomTypeId("0001");
		condition.setRatePlanId(90257);
		condition.setNumberOfRooms(1);
		condition.setTotalPrice(new BigDecimal(500));
		condition.setEarliestArrivalTime(date3);
		condition.setLatestArrivalTime(date4);
		
	
	
	return condition;
}
 
Example 19
@Override
public CreateOrderCondition getConditon() {
	CreateOrderCondition condition = new CreateOrderCondition();
		Date date = new Date();
		date = util.Tool.addDate(date, 1);
		Date date2 = util.Tool.addDate(date, 1);
		Date date3 = util.Tool.addDate(date, 0);
		date3.setHours(15);
		date3.setMinutes(0);
		date3.setSeconds(0);
		Date date4 = util.Tool.addDate(date, 0);
		date4.setHours(17);
		date4.setMinutes(0);
		date4.setSeconds(0);
		
		condition.setHotelId("10101129");
		condition.setRoomTypeId("0010");
		condition.setRatePlanId(145742);
		condition.setTotalPrice(new BigDecimal(600));
		condition.setAffiliateConfirmationId("my-order-id-2");
		
		condition.setArrivalDate(date);
		condition.setConfirmationType(elong.EnumConfirmationType.NotAllowedConfirm);
		condition.setContact(getContact());
		condition.setCreditCard(getCreditCard());
		condition.setCurrencyCode(elong.EnumCurrencyCode.HKD);
		condition.setCustomerIPAddress("211.151.230.21");
		condition.setCustomerType(elong.EnumGuestTypeCode.OtherForeign);
		condition.setDepartureDate(date2);
		condition.setEarliestArrivalTime(date3);
		condition.setExtendInfo(null);			
		condition.setInvoice(null);
		condition.setIsForceGuarantee(false);
		condition.setIsGuaranteeOrCharged(false);
		condition.setIsNeedInvoice(false);
		condition.setLatestArrivalTime(date4);
		condition.setNightlyRates(null);
		condition.setNoteToElong("");
		condition.setNoteToHotel(null);
		condition.setNumberOfCustomers(1);
		condition.setNumberOfRooms(1);
		condition.setOrderRooms( getRooms() );
		condition.setPaymentType(elong.EnumPaymentType.SelfPay);
		condition.setSupplierCardNo(null);
		
		
	
	return condition;
}
 
Example 20
protected Date nextIntervalDate(Date intervalMinDate, DateIntervalType intervalType, int intervals) {
    Date intervalMaxDate = new Date(intervalMinDate.getTime());

    if (MILLENIUM.equals(intervalType)) {
        intervalMaxDate.setYear(intervalMinDate.getYear() + 1000 * intervals);
    }
    else if (CENTURY.equals(intervalType)) {
        intervalMaxDate.setYear(intervalMinDate.getYear() + 100 * intervals);
    }
    else if (DECADE.equals(intervalType)) {
        intervalMaxDate.setYear(intervalMinDate.getYear() + 10 * intervals);
    }
    else if (YEAR.equals(intervalType)) {
        intervalMaxDate.setYear(intervalMinDate.getYear() +  intervals);
    }
    else if (QUARTER.equals(intervalType)) {
        intervalMaxDate.setMonth(intervalMinDate.getMonth() + 3 * intervals);
    }
    else if (MONTH.equals(intervalType)) {
        intervalMaxDate.setMonth(intervalMinDate.getMonth() + intervals);
    }
    else if (WEEK.equals(intervalType)) {
        intervalMaxDate.setDate(intervalMinDate.getDate() + 7 * intervals);
    }
    else if (DAY.equals(intervalType) || DAY_OF_WEEK.equals(intervalType)) {
        intervalMaxDate.setDate(intervalMinDate.getDate() + intervals);
    }
    else if (HOUR.equals(intervalType)) {
        intervalMaxDate.setHours(intervalMinDate.getHours() + intervals);
    }
    else if (MINUTE.equals(intervalType)) {
        intervalMaxDate.setMinutes(intervalMinDate.getMinutes() + intervals);
    }
    else if (SECOND.equals(intervalType)) {
        intervalMaxDate.setSeconds(intervalMinDate.getSeconds() + intervals);
    }
    else {
        // Default to year to avoid infinite loops
        intervalMaxDate.setYear(intervalMinDate.getYear() + intervals);
    }
    return intervalMaxDate;
}