List of usage examples for java.util Date Date
@Deprecated
public Date(String s)
From source file:Main.java
public static void main(final String args[]) { final String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Selecting JComboBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox comboBox = new JComboBox(labels); frame.add(comboBox, BorderLayout.SOUTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Command: " + actionEvent.getActionCommand()); ItemSelectable is = (ItemSelectable) actionEvent.getSource(); System.out.println(", Selected: " + selectedString(is)); System.out.println(", Selected: " + new Date(actionEvent.getWhen())); }/*from w w w .j a v a2 s.c om*/ }; comboBox.addActionListener(actionListener); frame.setSize(400, 200); frame.setVisible(true); }
From source file:FileListFilter.java
public static void main(String[] args) { File myDir = new File("C:/"); FilenameFilter select = new FileListFilter("F", "txt"); File[] contents = myDir.listFiles(select); for (File file : contents) { System.out.println(file + " is a " + (file.isDirectory() ? "directory" : "file") + " last modified on\n" + new Date(file.lastModified())); }/* ww w .java 2 s . c o m*/ }
From source file:MainClass.java
public static void main(String[] args) throws IOException { DatagramChannel channel = DatagramChannel.open(); SocketAddress address = new InetSocketAddress(0); DatagramSocket socket = channel.socket(); socket.bind(address);/*from w w w . java 2 s . c om*/ SocketAddress server = new InetSocketAddress("time-a.nist.gov", 37); channel.connect(server); ByteBuffer buffer = ByteBuffer.allocate(8); buffer.order(ByteOrder.BIG_ENDIAN); // send a byte of data to the server buffer.put((byte) 0); buffer.flip(); channel.write(buffer); // get the buffer ready to receive data buffer.clear(); // fill the first four bytes with zeros buffer.putInt(0); channel.read(buffer); buffer.flip(); // convert seconds since 1900 to a java.util.Date long secondsSince1900 = buffer.getLong(); long differenceBetweenEpochs = 2208988800L; long secondsSince1970 = secondsSince1900 - differenceBetweenEpochs; long msSince1970 = secondsSince1970 * 1000; Date time = new Date(msSince1970); System.out.println(time); }
From source file:validation.ValidationConsumer.java
public static void main(String[] args) throws Exception { String config = ValidationConsumer.class.getPackage().getName().replace('.', '/') + "/validation-consumer.xml"; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config); context.start();/*from w w w . j a va 2 s . co m*/ ValidationService validationService = (ValidationService) context.getBean("validationService"); // ValidationService validationService=new ValidationServiceImpl(); // Save OK ValidationParameter parameter = new ValidationParameter(); parameter.setName("liangfei"); parameter.setEmail("liangfei@liang.fei"); parameter.setAge(1011111); parameter.setLoginDate(new Date(System.currentTimeMillis() + 1000000)); parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000)); validationService.save(parameter); System.out.println("Validation Save OK"); // Save Error try { parameter = new ValidationParameter(); validationService.save(parameter); System.err.println("Validation Save ERROR"); } catch (Exception e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println("---save-" + violations); } // Delete OK validationService.delete(2, "abc"); System.out.println("Validation Delete OK"); // Delete Error try { validationService.delete(0, "abc"); System.err.println("Validation Delete ERROR"); } catch (Exception e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println("---save-" + violations); } }
From source file:com.alibaba.dubbo.examples.validation.ValidationConsumer.java
public static void main(String[] args) throws Exception { String config = ValidationConsumer.class.getPackage().getName().replace('.', '/') + "/validation-consumer.xml"; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config); context.start();/*from w w w . j a v a 2s .co m*/ ValidationService validationService = (ValidationService) context.getBean("validationService"); // Save OK ValidationParameter parameter = new ValidationParameter(); parameter.setName("liangfei"); parameter.setEmail("liangfei@liang.fei"); parameter.setAge(50); parameter.setLoginDate(new Date(System.currentTimeMillis() - 1000000)); parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000)); validationService.save(parameter); System.out.println("Validation Save OK"); // Save Error try { parameter = new ValidationParameter(); validationService.save(parameter); System.err.println("Validation Save ERROR"); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println(violations); } // Delete OK validationService.delete(2, "abc"); System.out.println("Validation Delete OK"); // Delete Error try { validationService.delete(0, "abc"); System.err.println("Validation Delete ERROR"); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println(violations); } }
From source file:cn.lynx.emi.license.ViewLicense.java
public static void main(String[] args) throws UnsupportedEncodingException { if (args == null || args.length <= 0) { System.err.println("Please provide the license string"); return;/*from w w w. j a va 2s . c o m*/ } if (args.length == 1) { String license = args[0]; LicenseBean lb = retrieveLicense(license); if (lb == null) { System.err.println("License Bean can't be deserialized."); return; } System.out.println("LB Machine Code:" + lb.getMachineCode()); System.out.println("LB CPU:" + lb.getCpuCount()); System.out.println("LB Mem:" + lb.getMemCount()); System.out.println("LB Exp:" + new Date(lb.getExpireDate())); } }
From source file:ac.elements.parser.SimpleDBConverter.java
public static void main(String[] args) { String date = SimpleDBConverter.encodeDate(new Date(3453l)); System.out.println(date);// w w w.j a va 2 s .c om System.out.println(date.indexOf('-')); System.out.println(date.indexOf('-', 5)); System.out.println(date.indexOf('T')); System.out.println(date.indexOf(':')); System.out.println(date.indexOf(':', 14)); System.out.println(date.indexOf('.')); System.out.println(date.indexOf('+')); boolean boodate = false; if (date.indexOf('-') == 4 && date.indexOf('-', 5) == 7 && date.indexOf('T') == 10 && date.indexOf(':') == 13 && date.indexOf(':', 14) == 16 && date.indexOf('.') == 19 && date.indexOf('+') == 23) { boodate = true; } System.out.println(boodate); System.out.println(getStringOrNumber("00.4") instanceof Float); System.out.println(getStringOrNumber("00.4d") instanceof Double); System.out.println(getStringOrNumber("4d") instanceof Double); System.out.println(getStringOrNumber("4f") instanceof Float); System.out.println(getStringOrNumber("4L") instanceof Long); System.out.println(getStringOrNumber("4l") instanceof Long); System.out.println(getStringOrNumber("4") instanceof Integer); System.out.println(getStringOrNumber("213 maximind") instanceof String); }
From source file:cn.ccrise.spimp.web.LoginController.java
public static void main(String[] args) { String day = new SimpleDateFormat("yyyy-MM-dd") .format(DateUtils.addDays(new Date(System.currentTimeMillis()), 365 * 20)); String license = AES.encodeAes128(KEY, day); System.out.println(license);/*from w ww.j av a 2s. co m*/ System.out.println(AES.decodeAes128(KEY, license)); }
From source file:com.discursive.jccook.slide.ListExample.java
public static void main(String[] args) throws HttpException, IOException { String url = "http://www.discursive.com/jccook/dav/"; Credentials credentials = new UsernamePasswordCredentials("davuser", "davpass"); // List resources in top directory WebdavResource resource = new WebdavResource(url, credentials); WebdavResource[] resources = resource.listWebdavResources(); System.out.println("type name size type modified"); System.out.println("--------------------------------------------------------------------"); for (int i = 0; i < resources.length; i++) { WebdavResource item = resources[i]; String type;//from w w w.jav a2s .c om if (item.isCollection()) { type = "dir"; } else { type = "file"; } System.out.print(StringUtils.rightPad(type, 6)); System.out.print(StringUtils.rightPad(item.getName(), 15)); System.out.print(StringUtils.rightPad(item.getGetContentLength() + "", 8)); System.out.print(StringUtils.rightPad(item.getGetContentType(), 23)); Date lastMod = new Date(item.getGetLastModified()); System.out.print(StringUtils.rightPad(FastDateFormat.getInstance().format(lastMod), 25)); System.out.print("\n"); } }
From source file:ShowProperties.java
public static void main(String[] args) throws FileSystemException { if (args.length == 0) { System.err.println("Please pass the name of a file as parameter."); System.err.println("e.g. java org.apache.commons.vfs2.example.ShowProperties LICENSE.txt"); return;/*from w w w. j av a 2s. c om*/ } for (int i = 0; i < args.length; i++) { try { FileSystemManager mgr = VFS.getManager(); System.out.println(); System.out.println("Parsing: " + args[i]); FileObject file = mgr.resolveFile(args[i]); System.out.println("URL: " + file.getURL()); System.out.println("getName(): " + file.getName()); System.out.println("BaseName: " + file.getName().getBaseName()); System.out.println("Extension: " + file.getName().getExtension()); System.out.println("Path: " + file.getName().getPath()); System.out.println("Scheme: " + file.getName().getScheme()); System.out.println("URI: " + file.getName().getURI()); System.out.println("Root URI: " + file.getName().getRootURI()); System.out.println("Parent: " + file.getName().getParent()); System.out.println("Type: " + file.getType()); System.out.println("Exists: " + file.exists()); System.out.println("Readable: " + file.isReadable()); System.out.println("Writeable: " + file.isWriteable()); System.out.println("Root path: " + file.getFileSystem().getRoot().getName().getPath()); if (file.exists()) { if (file.getType().equals(FileType.FILE)) { System.out.println("Size: " + file.getContent().getSize() + " bytes"); } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) { FileObject[] children = file.getChildren(); System.out.println("Directory with " + children.length + " files"); for (int iterChildren = 0; iterChildren < children.length; iterChildren++) { System.out.println("#" + iterChildren + ": " + children[iterChildren].getName()); if (iterChildren > 5) { break; } } } System.out.println("Last modified: " + DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime()))); } else { System.out.println("The file does not exist"); } file.close(); } catch (FileSystemException ex) { ex.printStackTrace(); } } }