List of usage examples for java.util Date Date
@Deprecated
public Date(String s)
From source file:MainClass.java
public static void main(String[] args) { try {//from www .j a va2s . c o m ZipFile zf = new ZipFile("your.zip"); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); String name = ze.getName(); Date lastModified = new Date(ze.getTime()); long uncompressedSize = ze.getSize(); long compressedSize = ze.getCompressedSize(); int method = ze.getMethod(); if (method == ZipEntry.STORED) { System.out.println(name + " was stored at " + lastModified); System.out.println("with a size of " + uncompressedSize + " bytes"); } else if (method == ZipEntry.DEFLATED) { System.out.println(name + " was deflated at " + lastModified); System.out.println("from " + uncompressedSize + " bytes to " + compressedSize + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%"); } else { System.out.println(name + " was compressed using an unrecognized method at " + lastModified); System.out.println("from " + uncompressedSize + " bytes to " + compressedSize + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%"); } } } catch (IOException ex) { System.err.println(ex); } }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); Date nowDate = now.getTime(); long twoHoursByMillis = 2 * HOUR; long thirtyMinutesByMillis = 30 * MINUTE; Date twoHoursAndThirtyMinutesFromNow = new Date(twoHoursByMillis + thirtyMinutesByMillis); System.out.println(String.format("now %s and later %s", nowDate, twoHoursAndThirtyMinutesFromNow)); long ms = 10304004543l; StringBuilder text = new StringBuilder(""); if (ms > DAY) { text.append(ms / DAY).append(" days "); ms %= DAY;//from w ww. java2 s . c om } if (ms > HOUR) { text.append(ms / HOUR).append(" hours "); ms %= HOUR; } if (ms > MINUTE) { text.append(ms / MINUTE).append(" minutes "); ms %= MINUTE; } if (ms > SECOND) { text.append(ms / SECOND).append(" seconds "); ms %= SECOND; } text.append(ms + " ms"); System.out.println(text.toString()); }
From source file:ColumnSample.java
public static void main(String args[]) { TableModel model = new AbstractTableModel() { Icon icon1 = new ImageIcon("TreeCollapsed.gif"); Icon icon2 = new ImageIcon("TreeExpanded.gif"); Object rowData[][] = { { "1", "ichi", Boolean.TRUE, new Date("01/01/2000"), icon1 }, { "2", "ni", Boolean.TRUE, new Date("04/15/1999"), icon2 }, { "3", "san", Boolean.FALSE, new Date("12/07/1941"), icon2 }, { "4", "shi", Boolean.TRUE, new Date("02/29/2000"), icon1 }, { "5", "go", Boolean.FALSE, new Date("05/23/1995"), icon1 }, }; String columnNames[] = { "English", "Japanese", "Boolean", "Date", "ImageIcon" }; public int getColumnCount() { return columnNames.length; }/* w ww . j a va 2 s. c om*/ public String getColumnName(int column) { return columnNames[column]; } public int getRowCount() { return rowData.length; } public Object getValueAt(int row, int column) { return rowData[row][column]; } public Class getColumnClass(int column) { return (getValueAt(0, column).getClass()); } }; JFrame frame = new JFrame("Column Renderer Table"); JTable table = new JTable(model); JScrollPane scrollPane = new JScrollPane(table); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(400, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) throws Exception { int c;//w ww . j a v a2s.co m URL hp = new URL("http://www.internic.net"); URLConnection hpCon = hp.openConnection(); long d = hpCon.getDate(); if (d == 0) System.out.println("No date information."); else System.out.println("Date: " + new Date(d)); System.out.println("Content-Type: " + hpCon.getContentType()); d = hpCon.getExpiration(); if (d == 0) System.out.println("No expiration information."); else System.out.println("Expires: " + new Date(d)); d = hpCon.getLastModified(); if (d == 0) System.out.println("No last-modified information."); else System.out.println("Last-Modified: " + new Date(d)); int len = hpCon.getContentLength(); if (len == -1) System.out.println("Content length unavailable."); else System.out.println("Content-Length: " + len); if (len != 0) { InputStream input = hpCon.getInputStream(); int i = len; while (((c = input.read()) != -1)) { // && (--i > 0)) { System.out.print((char) c); } input.close(); } else { System.out.println("No content available."); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { File f = new File("name.txt"); if (!f.exists()) { System.out.println("File not found."); return;/*from w ww . j ava2 s . c om*/ } if (f.canRead()) System.out.println(" Readable"); else System.out.println(" Not Readable"); if (f.canWrite()) System.out.println(" Writable"); else System.out.println(" Not Writable"); System.out.println(" Last modified on " + new Date(f.lastModified())); long t = Calendar.getInstance().getTimeInMillis(); if (!f.setLastModified(t)) System.out.println("Can't set time."); if (!f.setReadOnly()) System.out.println("Can't set to read-only."); if (f.canRead()) System.out.println(" Readable"); else System.out.println(" Not Readable"); if (f.canWrite()) System.out.println(" Writable"); else System.out.println(" Not Writable"); System.out.println(" Last modified on " + new Date(f.lastModified())); if (!f.setWritable(true, false)) System.out.println("Can't return to read/write."); if (f.canRead()) System.out.println(" Readable"); else System.out.println(" Not Readable"); if (f.canWrite()) System.out.println(" Writable"); else System.out.println(" Not Writable"); }
From source file:Main.java
public static void main(String[] args) throws Exception { ZipFile zf = new ZipFile("a.zip"); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); String name = ze.getName(); long uncompressedSize = ze.getSize(); long compressedSize = ze.getCompressedSize(); long crc = ze.getCrc(); int method = ze.getMethod(); String comment = ze.getComment(); System.out.println(name + " was stored at " + new Date(ze.getTime())); if (method == ZipEntry.STORED) { System.out.println("with a size of " + uncompressedSize + " bytes"); } else if (method == ZipEntry.DEFLATED) { System.out.println("from " + uncompressedSize + " bytes to " + compressedSize); } else {// ww w.j ava 2 s. c om System.out.println("from " + uncompressedSize + " bytes to " + compressedSize); } System.out.println("Its CRC is " + crc); if (comment != null && !comment.equals("")) { System.out.println(comment); } if (ze.isDirectory()) { System.out.println(name + " is a directory"); } } }
From source file:Main.java
public static void main(String[] args) throws IOException { JarFile jf = new JarFile("a.jar"); Enumeration e = jf.entries(); while (e.hasMoreElements()) { JarEntry je = (JarEntry) e.nextElement(); System.out.println(je.getName()); long uncompressedSize = je.getSize(); long compressedSize = je.getCompressedSize(); long crc = je.getCrc(); int method = je.getMethod(); String comment = je.getComment(); System.out.println(new Date(je.getTime())); System.out.println("from " + uncompressedSize + " bytes to " + compressedSize); if (method == ZipEntry.STORED) { System.out.println("ZipEntry.STORED"); } else if (method == ZipEntry.DEFLATED) { System.out.println(ZipEntry.DEFLATED); }//from ww w.j av a2 s . co m System.out.println("Its CRC is " + crc); System.out.println(comment); System.out.println(je.isDirectory()); Attributes a = je.getAttributes(); if (a != null) { Object[] nameValuePairs = a.entrySet().toArray(); for (int j = 0; j < nameValuePairs.length; j++) { System.out.println(nameValuePairs[j]); } } System.out.println(); } }
From source file:EditableColumn.java
public static void main(String args[]) { TableModel model = new AbstractTableModel() { Icon icon1 = new ImageIcon("TreeCollapsed.gif"); Icon icon2 = new ImageIcon("TreeExpanded.gif"); Object rowData[][] = { { new Integer(1), "ichi", Boolean.TRUE, new Date("01/01/2000"), icon1 }, { new Integer(2), "ni", Boolean.TRUE, new Date("04/15/1999"), icon2 }, { new Integer(3), "san", Boolean.FALSE, new Date("12/07/1941"), icon2 }, { new Integer(4), "shi", Boolean.TRUE, new Date("02/29/2000"), icon1 }, { new Integer(5), "go", Boolean.FALSE, new Date("05/23/1995"), icon1 }, }; String columnNames[] = { "English", "Japanese", "Boolean", "Date", "ImageIcon" }; public int getColumnCount() { return columnNames.length; }//from www. ja va2s. c om public String getColumnName(int column) { return columnNames[column]; } public int getRowCount() { return rowData.length; } public Object getValueAt(int row, int column) { return rowData[row][column]; } public Class getColumnClass(int column) { return (getValueAt(0, column).getClass()); } public void setValueAt(Object value, int row, int column) { rowData[row][column] = value; } public boolean isCellEditable(int row, int column) { return (column != 4); } }; JFrame frame = new JFrame("Column Renderer Table"); JTable table = new JTable(model); JScrollPane scrollPane = new JScrollPane(table); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(400, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Calendar someTime = Calendar.getInstance(); someTime.set(Calendar.HOUR_OF_DAY, 17); someTime.set(Calendar.MINUTE, 0); someTime.set(Calendar.SECOND, 0); // convert it to java epoch date Date someDate = toEpochDate(someTime); // create a date object from java.sql.Time Date fromSqlTime = new Date(Time.valueOf("17:00:00").getTime()); // now do the comparison System.out.println("Some Date: " + someDate.toString()); System.out.println("Sql Time: " + fromSqlTime.toString()); System.out.println("Are they equal? " + someDate.equals(fromSqlTime)); }
From source file:MainClass.java
public static void main(String[] args) { File myDir = new File("C:/"); // Define a filter for java source files beginning with F FilenameFilter select = new FileListFilter("F", "java"); File[] contents = myDir.listFiles(select); if (contents != null) { System.out.println(//from ww w . j a v a2s . c o m "\nThe " + contents.length + " matching items in the directory, " + myDir.getName() + ", are:"); for (File file : contents) { System.out.println(file + " is a " + (file.isDirectory() ? "directory" : "file") + " last modified on\n" + new Date(file.lastModified())); } } else { System.out.println(myDir.getName() + " is not a directory"); } return; }