List of usage examples for java.util Calendar DATE
int DATE
To view the source code for java.util Calendar DATE.
Click Source Link
get
and set
indicating the day of the month. From source file:DateUtils.java
public static final String dateToString(Date dt, String dateformat) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(dt);/* w w w .j av a 2 s . c o m*/ StringBuffer ret = new StringBuffer(); String separator = new String(); if (dateformat.equals(DateUtils.FORMAT_YYYYMMDD)) { separator = "-"; } if (dateformat.equals(DateUtils.FORMAT_YYYYMMDD_SLASHES)) { separator = "/"; } ret.append(cal.get(Calendar.YEAR)); ret.append(separator); ret.append(cal.get(Calendar.MONTH) + 1); ret.append(separator); ret.append(cal.get(Calendar.DATE)); return ret.toString(); }
From source file:com.glaf.core.util.CalendarUtils.java
/** * ?/* w ww .j ava 2 s . co m*/ * * @param date * @param day * @return */ private static Date getDateBefore(Date date, int day) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.DATE, cal.get(Calendar.DATE) - day); return cal.getTime(); }
From source file:net.seratch.taskun.util.CalendarUtil.java
public static Calendar getCalendar(int yyyy, int mm, int dd) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, yyyy);//www .j a v a 2 s . c om cal.set(Calendar.MONTH, mm - 1); cal.set(Calendar.DATE, dd); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal; }
From source file:com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImplTest.java
/** * Runs actions before test is initialized. * //from w w w . j av a 2 s . co m * @throws java.lang.Exception */ @BeforeClass public static void setUpBeforeClass() throws Exception { logger.info("Beginning tests for com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImpl"); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -3); yesterday = dateFormat.format(cal.getTime()); StringBuilder canonicalYesterday = new StringBuilder(yesterday); canonicalYesterday.replace(10, 11, "%20"); query = "search?jql=updatedDate%3E=%22" + canonicalYesterday + "%22+order+by+updated"; }
From source file:io.github.bluemarlin.util.BluemarlineUtil.java
public static Date getDateInThePast(int days) { Date dateNow = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(dateNow);//from w w w .ja va 2s .c o m cal.add(Calendar.DATE, -days); Date d = cal.getTime(); return d; }
From source file:com.cemeterylistingswebtest.test.services.LoginServiceTest.java
@Test public void AuthenticateTest() { loginServ = ctx.getBean(LoginService.class); repo = ctx.getBean(SubscriberRepository.class); //create subscribers userRepo = ctx.getBean(UserRoleRepository.class); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2008); calendar.set(Calendar.MONTH, Calendar.FEBRUARY); calendar.set(Calendar.DATE, 4); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); UserRole user = new UserRole.Builder().setLevel(1).build(); //userRepo.save(user); //userRoleID = user.getUserRoleID(); Subscriber newSub = new Subscriber.Builder().setEmail("manfredOsulivan@horseRaddish.com") .setFirstName("Manfred").setSurname("Osulivan").setPwd("jesus").setUsername("ManiFredOssy") .setSubscriptionDate(javaSqlDate).setUserRoleID(user).build(); repo.save(newSub);/*from w ww.ja v a 2 s . com*/ id = newSub.getSubscriberID(); Assert.assertTrue(loginServ.authenticate(newSub.getUsername(), newSub.getPwd()), "Login successful"); Assert.assertFalse(loginServ.authenticate(newSub.getUsername(), ""), "Login Failed; no password"); Assert.assertFalse(loginServ.authenticate("", newSub.getPwd()), "Login Failed ; no username"); Assert.assertFalse(loginServ.authenticate("", ""), "Login Failed no username or password"); }
From source file:com.cemeterylistingswebtest.test.domain.SubscriberTest.java
@Test public void create() { System.out.println("Subscriber Test"); repo = ctx.getBean(SubscriberRepository.class); userRepo = ctx.getBean(UserRoleRepository.class); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2008); calendar.set(Calendar.MONTH, Calendar.FEBRUARY); calendar.set(Calendar.DATE, 4); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); UserRole user = new UserRole.Builder().setLevel(1).build(); //userRepo.save(user); //userRoleID = user.getUserRoleID(); Subscriber newSub = new Subscriber.Builder().setEmail("manfredOsulivan@horseRaddish.com") .setFirstName("Manfred").setSurname("Osulivan").setPwd("jesus").setUsername("ManiFredOssy") .setSubscriptionDate(javaSqlDate).setUserRoleID(user).build(); repo.save(newSub);/*from w ww. j a v a2 s. c o m*/ id = newSub.getSubscriberID(); }
From source file:co.mafiagame.engine.util.PurgeTimer.java
@Override public void run() { Calendar twoDayAgo = Calendar.getInstance(); twoDayAgo.add(Calendar.DATE, -2); Calendar oneDayAgo = Calendar.getInstance(); oneDayAgo.add(Calendar.DATE, -1); gameContainer.getGames().forEach(game -> { Calendar gameLastUpdate = Calendar.getInstance(); gameLastUpdate.setTime(game.getLastUpdate()); if (twoDayAgo.after(gameLastUpdate)) commandExecutor.run(game.getInterfaceContext(), Constants.CMD.Internal.PURGE, new EmptyContext(game.getInterfaceContext(), game)); else if (oneDayAgo.after(gameLastUpdate)) commandExecutor.run(game.getInterfaceContext(), Constants.CMD.Internal.PURGE_ALARM, new EmptyContext(game.getInterfaceContext(), game)); });/* w ww. j a va 2 s .c o m*/ }
From source file:com.keybox.manage.db.SessionAuditDB.java
/** * deletes audit history for users if after time set in properties file * * @param con DB connection/* ww w .j ava 2s. c om*/ */ public static void deleteAuditHistory(Connection con) { try { //delete logs with no terminal entries PreparedStatement stmt = con.prepareStatement( "delete from session_log where id not in (select session_id from terminal_log)"); stmt.execute(); //take today's date and subtract how many days to keep history Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, (-1 * Integer.parseInt(AppConfig.getProperty("deleteAuditLogAfter")))); //subtract java.sql.Date date = new java.sql.Date(cal.getTimeInMillis()); stmt = con.prepareStatement("delete from session_log where session_tm < ?"); stmt.setDate(1, date); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } }
From source file:com.linuxbox.enkive.teststats.StatsDayGrainTest.java
@BeforeClass public static void setUp() throws ParseException, GathererException { coll = TestHelper.GetTestCollection(); client = TestHelper.BuildClient();// w w w .j a va2 s .c o m grain = new DayConsolidator(client); List<Map<String, Object>> stats = (new HourConsolidator(client)).consolidateData(); Map<String, Object> timeMap = new HashMap<String, Object>(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 1); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR, 0); for (int i = 0; i < 10; i++) { if (i == 5) { cal.add(Calendar.DATE, -1); } timeMap.put(CONSOLIDATION_MAX, cal.getTime()); timeMap.put(CONSOLIDATION_MIN, cal.getTime()); for (Map<String, Object> data : stats) { data.put(STAT_TIMESTAMP, timeMap); } client.storeData(stats); } dataCount = coll.count(); }