List of usage examples for java.util Date getDay
@Deprecated public int getDay()
From source file:Main.java
public static boolean isSameDay(Date date1, Date date2) { return date1.getDay() == date2.getDay() && date1.getMonth() == date2.getMonth() && date1.getYear() == date2.getYear(); }
From source file:Main.java
public static boolean isSameDay(Date d1, Date d2) { return d1.getDay() == d2.getDay() && d1.getMonth() == d2.getMonth() && d1.getYear() == d2.getYear(); }
From source file:Main.java
/** * @param date//ww w .j av a 2 s . c om * * @return */ public static String getFormatedDate(Date date) { return date.getYear() + "-" + date.getMonth() + "-" + date.getDay() + " - At " + date.getHours() + ":" + date.getMinutes(); }
From source file:ch.ethz.inf.vs.android.g54.a4.util.SnapshotCache.java
private static String constructFileName(String name) { Date d = new Date(); return String.format("%d-%d-%d_%d-%d-%d_%s.%s", d.getYear() + 1900, d.getMonth(), d.getDay(), d.getHours(), d.getMinutes(), d.getSeconds(), name, FILE_EXTENSION); }
From source file:controllers.CNBCProxy.java
private static String CalculateDateFormat(long millis) { // Set helping arrays String[] monthArr = new String[12]; String[] dayArr = new String[7]; // Set month names monthArr[0] = "January"; monthArr[1] = "February"; monthArr[2] = "March"; monthArr[3] = "April"; monthArr[4] = "May"; monthArr[5] = "June"; monthArr[6] = "July"; monthArr[7] = "August"; monthArr[8] = "September"; monthArr[9] = "October"; monthArr[10] = "November"; monthArr[11] = "December"; // Set day names dayArr[0] = "Sunday"; dayArr[1] = "Monday"; dayArr[2] = "Tuesday"; dayArr[3] = "Wednesday"; dayArr[4] = "Thursday"; dayArr[5] = "Friday"; dayArr[6] = "Saturday"; /** Create Date object with random date, in order to calculate date of article like the "setTime()" function in Javascript (date since January 1, 1970 00:00:00 gmt) **///from w ww.j a v a2 s . c om Date dateObj = new Date(92, 1, 10); // Add long number to get article's date dateObj.setTime(millis); StringBuilder date = new StringBuilder(); date.append(dayArr[dateObj.getDay()]).append(", ").append(Integer.toString(dateObj.getDate())).append(" ") .append(monthArr[dateObj.getMonth()]).append(" ").append(Integer.toString(dateObj.getYear() + 1900)) .append(" "); // 1900 added to year(see getYear() method's documentation) String hours; String midnight; if (dateObj.getHours() > 12) { if (dateObj.getHours() - 12 < 10) { hours = "0" + Integer.toString(dateObj.getHours() - 12); } else { hours = Integer.toString(dateObj.getHours() - 12); } midnight = "PM"; } else { if (dateObj.getHours() < 10) { hours = "0" + Integer.toString(dateObj.getHours()); } else { hours = Integer.toString(dateObj.getHours()); } midnight = "AM"; } date.append(hours).append(":").append(Integer.toString(dateObj.getMinutes())) .append(" " + midnight + " ET"); return date.toString(); }
From source file:nz.co.fortytwo.freeboard.server.util.Util.java
/** * Attempt to set the system time using the GPS time * * @param sen//from ww w. java 2s .c o m */ @SuppressWarnings("deprecation") public static void checkTime(RMCSentence sen) { if (timeSet) { return; } try { sen.getPosition(); } catch (DataNotAvailableException e) { return; } try { net.sf.marineapi.nmea.util.Date dayNow = sen.getDate(); //if we need to set the time, we will be WAAYYY out //we only try once, so we dont get lots of native processes spawning if we fail props = getConfig(null); if (props.getProperty(Constants.DEMO).equals("false")) { if (System.getProperty("os.name").startsWith("Windows")) { // includes: Windows 2000, Windows 95, Windows 98, Windows NT, Windows Vista, Windows XP // a Win system will already have the time set. return; } } timeSet = true; Date date = new Date(); net.sf.marineapi.nmea.util.Date gpsDate; //so we need to set the date and time net.sf.marineapi.nmea.util.Time gpsTime = sen.getTime(); gpsDate = sen.getDate(); String hh = pad(2, String.valueOf(gpsTime.getHour())); String mm = pad(2, String.valueOf(gpsTime.getMinutes())); String ss = pad(2, String.valueOf((int) gpsTime.getSeconds())); if (logger.isDebugEnabled()) { logger.debug("Setting current date to " + dayNow + " " + gpsTime); } String cmd = "sudo date --utc " + pad(2, String.valueOf(gpsDate.getMonth())) + pad(2, String.valueOf(gpsDate.getDay())) + hh + mm + gpsDate.getYear() + "." + ss; System.out.println("Setting date " + cmd); // only set the system time if we are not running demo if (props.getProperty(Constants.DEMO).equals("false")) { Runtime.getRuntime().exec(cmd.split(" "));// MMddhhmm[[yy]yy] } if (logger.isDebugEnabled()) { logger.debug("Executed date setting command:" + cmd); } } catch (Exception e) { logger.error(e.getMessage(), e); } }
From source file:org.shengrui.oa.util.UtilDateTime.java
/** * /* w w w. j a va 2s . c o m*/ * @param date * @param daySeed * @return */ @SuppressWarnings("deprecation") public static List<Date> getDaysByDayBetweenRanges(Date beginDate, Date endDate, int day) { List<Date> result = new ArrayList<Date>(); List<Date> list = getDatesDateRange(beginDate, endDate); if (list != null && list.size() > 0) { for (Date date : list) { if (date.getDay() == day) { result.add(date); } } } return result; }
From source file:org.shengrui.oa.util.UtilDateTime.java
/** * /*from ww w .jav a 2 s. c o m*/ * @param weekNumOff * @return */ @SuppressWarnings("deprecation") public static List<String> getWeekDates(int weekOffset, String pattern) { List<String> list = new ArrayList<String>(); int dateNumOff = weekOffset * 7; SimpleDateFormat sdf = new SimpleDateFormat(pattern); Date now = new Date(); int day = now.getDay(); if (day == 0) day = 7; for (int i = 1; i <= 7; i++) { Date tmpDate = new Date(now.getYear(), now.getMonth(), now.getDate() - day + i + dateNumOff); list.add(sdf.format(tmpDate)); } return list; }
From source file:TimeFormatter.java
/** * Format the given date as a string, according to the given * format string.// w w w . j a v a 2 s . c o m * The format string is of the form used by the strftime(3) UNIX * call. * @param date The date to format * @param format The formatting string * @return the String with the formatted date. */ public static String format(Date date, String format) { StringBuffer buf = new StringBuffer(50); char ch; for (int i = 0; i < format.length(); i++) { ch = format.charAt(i); if (ch == '%') { ++i; if (i == format.length()) break; ch = format.charAt(i); if (ch == 'E') { // Alternate Era ++i; } else if (ch == 'Q') { // Alternate numeric symbols ++i; } if (i == format.length()) break; ch = format.charAt(i); switch (ch) { case 'A': buf.append(fullWeekDays[date.getDay()]); break; case 'a': buf.append(abrWeekDays[date.getDay()]); break; case 'B': buf.append(fullMonths[date.getMonth()]); break; case 'b': case 'h': buf.append(abrMonths[date.getMonth()]); break; case 'C': appendPadded(buf, (date.getYear() + 1900) / 100, 2); break; case 'c': buf.append(date.toLocaleString()); break; case 'D': buf.append(TimeFormatter.format(date, "%m/%d/%y")); break; case 'd': appendPadded(buf, date.getDate(), 2); break; case 'e': appendPadded(buf, date.getMonth() + 1, 2, ' '); break; case 'H': appendPadded(buf, date.getHours(), 2); break; case 'I': case 'l': int a = date.getHours() % 12; if (a == 0) a = 12; appendPadded(buf, a, 2, ch == 'I' ? '0' : ' '); break; case 'j': buf.append("[?]"); // No simple way to get this as of now break; case 'k': appendPadded(buf, date.getHours(), 2, ' '); break; case 'M': appendPadded(buf, date.getMinutes(), 2); break; case 'm': appendPadded(buf, date.getMonth() + 1, 2); break; case 'n': buf.append('\n'); break; case 'p': buf.append(date.getHours() < 12 ? "am" : "pm"); break; case 'R': buf.append(TimeFormatter.format(date, "%H:%M")); break; case 'r': buf.append(TimeFormatter.format(date, "%l:%M%p")); break; case 'S': appendPadded(buf, date.getSeconds(), 2); break; case 'T': buf.append(TimeFormatter.format(date, "%H:%M:%S")); break; case 't': buf.append('\t'); break; case 'U': case 'u': case 'V': case 'W': buf.append("[?]"); // Weekdays are a pain, especially // without day of year (0-365) ; break; case 'w': buf.append(date.getDay()); break; case 'X': buf.append(TimeFormatter.format(date, "%H:%M:%S")); break; case 'x': buf.append(TimeFormatter.format(date, "%B %e, %Y")); break; case 'y': appendPadded(buf, (date.getYear() + 1900) % 100, 2); break; case 'Y': appendPadded(buf, (date.getYear() + 1900), 4); break; case 'Z': String strdate = date.toString(); buf.append(strdate.substring(20, 23)); // (!) // There should be a better way // to do this... break; case '%': buf.append('%'); break; } } else { buf.append(ch); } } return buf.toString(); }
From source file:Interface.Teste.java
public void criacao() { DefaultCategoryDataset ds = new DefaultCategoryDataset(); ds.addValue(40.5, "maximo", "dia 1"); ds.addValue(38.2, "maximo", "dia 2"); ds.addValue(37.3, "maximo", "dia 3"); ds.addValue(31.5, "maximo", "dia 4"); ds.addValue(35.7, "maximo", "dia 5"); ds.addValue(42.5, "maximo", "dia 6"); // cria o grfico JFreeChart grafico = ChartFactory.createLineChart("Meu Grafico", "Dia", "Valor", ds, PlotOrientation.VERTICAL, true, true, false); try {/*from w w w. ja v a 2 s . co m*/ OutputStream arquivo = new FileOutputStream("grafico.png"); ChartUtilities.writeChartAsPNG(arquivo, grafico, 550, 400); arquivo.close(); } catch (Exception e) { e.printStackTrace(); } JPopupMenu pop = new JPopupMenu(); pop.add(new JMenuItem("1")); pop.add(new JMenuItem("2")); pop.add(new JMenuItem("3")); pop.add(new JMenuItem("4")); JPanel painel = new JPanel(); JButton botao = new JButton("teste"); JCalendar cal = new JCalendar(); botao.add(pop); painel.add(cal); painel.add(new ChartPanel(grafico)); //Calendar c = cal.getDate(); Date data = cal.getDate(); int dia = data.getDay(); System.out.println("" + dia); add(painel); }