List of usage examples for java.util Calendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:com.espertech.esper.client.util.DateTime.java
/** * Returns a calendar from a given string using the provided format. * @param datestring to parse/* w w w . j av a2 s .c om*/ * @param format to use for parsing * @return calendar */ public static Calendar toCalendar(String datestring, String format) { Date d = parse(datestring, format); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(d.getTime()); return cal; }
From source file:com.espertech.esper.client.util.DateTime.java
private static Calendar parseGetCal(String str, SimpleDateFormat format) { Date d = parse(str, format);//from w ww .j a v a2s . c o m if (d == null) { return null; } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(d.getTime()); return cal; }
From source file:Main.java
public static String getCurrentTimeString(int s) { //s=0 for star time s=1 for end time Calendar currentCalendar = Calendar.getInstance(); int hours = currentCalendar.get(Calendar.HOUR_OF_DAY); int minutes = currentCalendar.get(Calendar.MINUTE); if (minutes < 30) { currentCalendar.setTimeInMillis(currentCalendar.getTimeInMillis() + (30 - minutes) * 60 * 1000); }/* ww w .j ava 2s. c o m*/ if (minutes > 30) { currentCalendar.setTimeInMillis(currentCalendar.getTimeInMillis() + (60 - minutes) * 60 * 1000); } if (s == 1) currentCalendar.setTimeInMillis(currentCalendar.getTimeInMillis() + 30 * 60 * 1000); return timeFormat.format(currentCalendar.getTimeInMillis()); }
From source file:erpsystem.chart.Charts.java
private static Calendar getCurrentCalendar() { Calendar calendar = Calendar.getInstance(); long ct = System.currentTimeMillis(); calendar.setTimeInMillis(ct); return calendar; }
From source file:com.silverpeas.jcrutil.RandomGenerator.java
public static Calendar getCalendarAfter(Calendar date) { Calendar endDate = Calendar.getInstance(); endDate.setTimeInMillis(date.getTimeInMillis()); endDate.add(Calendar.DAY_OF_MONTH, 1 + random.nextInt(10)); return endDate; }
From source file:com.silverpeas.jcrutil.RandomGenerator.java
public static Calendar getCalendarBefore(Calendar date) { Calendar beforeDate = Calendar.getInstance(); beforeDate.setTimeInMillis(date.getTimeInMillis()); beforeDate.add(Calendar.DAY_OF_MONTH, -1 - random.nextInt(10)); return beforeDate; }
From source file:com.jredrain.tag.CronTag.java
/** * lonngtime?//w w w .j a v a 2s. com * @param value * @return */ public static String longtimeToDate(String value) { String s = ""; if (StringUtils.isNotBlank(value)) { long time = Long.valueOf(value); Calendar c = Calendar.getInstance(); c.setTimeInMillis(time); SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); s = dateformat.format(c.getTime()); } return s; }
From source file:Main.java
public static boolean isInTimeNow(int start, int end) { Calendar calendar = new ThreadLocal<Calendar>() { protected Calendar initialValue() { return Calendar.getInstance(); }/* www . j a v a 2s.c om*/ }.get(); long current = System.currentTimeMillis(); calendar.setTimeInMillis(current); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); long originToday = calendar.getTimeInMillis(); long distance = current - originToday; if (start <= distance && distance <= end) { return true; } return false; }
From source file:Main.java
/** * Get relativy days base on today, will return negative and positive * values./* w w w .j a v a 2s. c o m*/ * * @param d * @return */ public static long getRelativeDays(Date d) { Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); long curMilli = c.getTimeInMillis(); c.setTimeInMillis(d.getTime()); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); long dMilli = c.getTimeInMillis(); return (dMilli - curMilli) / (1 * 24 * 3600 * 1000); }
From source file:org.shept.util.FileUtils.java
/** * List the file directory as specified by the name filter and path directory * The maps keys contain modification dat for comparison * @param path// w w w .j a va 2s .co m * @param filePattern * @return */ public static SortedMap<Calendar, File> fileMapByDate(String path, String filePattern) { FileUtils fu = new FileUtils(); // needed for inner class SortedMap<Calendar, File> newFileMap = new TreeMap<Calendar, File>(); File fileDir = new File(path); if (null != path && fileDir.isDirectory()) { FileFilter filter = fu.new Filter(path, filePattern); File[] files = fileDir.listFiles(filter); for (int i = 0; i < files.length; i++) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(files[i].lastModified()); newFileMap.put(cal, files[i]); } } return newFileMap; }