List of usage examples for java.util Calendar MILLISECOND
int MILLISECOND
To view the source code for java.util Calendar MILLISECOND.
Click Source Link
get
and set
indicating the millisecond within the second. From source file:Main.java
public static void main(String[] args) { Calendar cal = new GregorianCalendar(); System.out.println(cal.get(Calendar.MILLISECOND)); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current full date time is : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR) + " " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND) + "." + now.get(Calendar.MILLISECOND)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar cal = new GregorianCalendar(); // Get the components of the time int hour12 = cal.get(Calendar.HOUR); // 0..11 int hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23 int min = cal.get(Calendar.MINUTE); // 0..59 int sec = cal.get(Calendar.SECOND); // 0..59 int ms = cal.get(Calendar.MILLISECOND); // 0..999 int ampm = cal.get(Calendar.AM_PM); // 0=AM, 1=PM }
From source file:MainClass.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println(calendar.get(Calendar.YEAR)); System.out.println(calendar.get(Calendar.MONTH)); System.out.println(calendar.get(Calendar.DATE)); System.out.println(calendar.get(Calendar.HOUR)); System.out.println(calendar.get(Calendar.MINUTE)); System.out.println(calendar.get(Calendar.SECOND)); System.out.println(calendar.get(Calendar.MILLISECOND)); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current Hour in 12 hour format is : " + now.get(Calendar.HOUR)); System.out.println("Current Hour in 24 hour format is : " + now.get(Calendar.HOUR_OF_DAY)); System.out.println("Current Minute is : " + now.get(Calendar.MINUTE)); System.out.println("Current Second is : " + now.get(Calendar.SECOND)); System.out.println("Current Millisecond is : " + now.get(Calendar.MILLISECOND)); }
From source file:MainClass.java
public static void main(String[] args) { // get a calendar using the default time zone and locale. Calendar calendar = Calendar.getInstance(); // set Date portion to January 1, 1970 calendar.set(Calendar.YEAR, 1970); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DATE, 1); // normalize the object calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); }
From source file:Main.java
public static void main(String[] args) { String input = "2014-05-04 09:10:40.321"; // Prepare the pattern String pattern = "yyyy-MM-dd HH:mm:ss.SSS"; SimpleDateFormat sdf = new SimpleDateFormat(pattern); // Parse the text into a Date object Date dt = sdf.parse(input, new ParsePosition(0)); System.out.println(dt);// w ww.j a v a 2 s . c om // Get the Calendar instance Calendar cal = Calendar.getInstance(); cal.setTime(dt); // Print time parts System.out.println("Hour:" + cal.get(Calendar.HOUR)); System.out.println("Minute:" + cal.get(Calendar.MINUTE)); System.out.println("Second:" + cal.get(Calendar.SECOND)); System.out.println("Millisecond:" + cal.get(Calendar.MILLISECOND)); }
From source file:MainClass.java
public static void main(String[] a) { Calendar calendar = new GregorianCalendar(); calendar.setTime(new Date()); System.out.println("ERA: " + calendar.get(Calendar.ERA)); System.out.println("YEAR: " + calendar.get(Calendar.YEAR)); System.out.println("MONTH: " + calendar.get(Calendar.MONTH)); System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR)); System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH)); System.out.println("DATE: " + calendar.get(Calendar.DATE)); System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH)); System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK)); System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH)); System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM)); System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND)); System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000))); System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000))); }
From source file:search.java
public static void main(String argv[]) { int optind;/* w w w . j ava 2 s . com*/ String subject = null; String from = null; boolean or = false; boolean today = false; int size = -1; for (optind = 0; optind < argv.length; optind++) { if (argv[optind].equals("-T")) { protocol = argv[++optind]; } else if (argv[optind].equals("-H")) { host = argv[++optind]; } else if (argv[optind].equals("-U")) { user = argv[++optind]; } else if (argv[optind].equals("-P")) { password = argv[++optind]; } else if (argv[optind].equals("-or")) { or = true; } else if (argv[optind].equals("-D")) { debug = true; } else if (argv[optind].equals("-f")) { mbox = argv[++optind]; } else if (argv[optind].equals("-L")) { url = argv[++optind]; } else if (argv[optind].equals("-subject")) { subject = argv[++optind]; } else if (argv[optind].equals("-from")) { from = argv[++optind]; } else if (argv[optind].equals("-today")) { today = true; } else if (argv[optind].equals("-size")) { size = Integer.parseInt(argv[++optind]); } else if (argv[optind].equals("--")) { optind++; break; } else if (argv[optind].startsWith("-")) { System.out.println("Usage: search [-D] [-L url] [-T protocol] [-H host] " + "[-U user] [-P password] [-f mailbox] " + "[-subject subject] [-from from] [-or] [-today]"); System.exit(1); } else { break; } } try { if ((subject == null) && (from == null) && !today && size < 0) { System.out.println("Specify either -subject, -from, -today, or -size"); System.exit(1); } // Get a Properties object Properties props = System.getProperties(); // Get a Session object Session session = Session.getInstance(props, null); session.setDebug(debug); // Get a Store object Store store = null; if (url != null) { URLName urln = new URLName(url); store = session.getStore(urln); store.connect(); } else { if (protocol != null) store = session.getStore(protocol); else store = session.getStore(); // Connect if (host != null || user != null || password != null) store.connect(host, user, password); else store.connect(); } // Open the Folder Folder folder = store.getDefaultFolder(); if (folder == null) { System.out.println("Cant find default namespace"); System.exit(1); } folder = folder.getFolder(mbox); if (folder == null) { System.out.println("Invalid folder"); System.exit(1); } folder.open(Folder.READ_ONLY); SearchTerm term = null; if (subject != null) term = new SubjectTerm(subject); if (from != null) { FromStringTerm fromTerm = new FromStringTerm(from); if (term != null) { if (or) term = new OrTerm(term, fromTerm); else term = new AndTerm(term, fromTerm); } else term = fromTerm; } if (today) { Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); c.set(Calendar.AM_PM, Calendar.AM); ReceivedDateTerm startDateTerm = new ReceivedDateTerm(ComparisonTerm.GE, c.getTime()); c.add(Calendar.DATE, 1); // next day ReceivedDateTerm endDateTerm = new ReceivedDateTerm(ComparisonTerm.LT, c.getTime()); SearchTerm dateTerm = new AndTerm(startDateTerm, endDateTerm); if (term != null) { if (or) term = new OrTerm(term, dateTerm); else term = new AndTerm(term, dateTerm); } else term = dateTerm; } if (size >= 0) { SizeTerm sizeTerm = new SizeTerm(ComparisonTerm.GT, size); if (term != null) { if (or) term = new OrTerm(term, sizeTerm); else term = new AndTerm(term, sizeTerm); } else term = sizeTerm; } Message[] msgs = folder.search(term); System.out.println("FOUND " + msgs.length + " MESSAGES"); if (msgs.length == 0) // no match System.exit(1); // Use a suitable FetchProfile FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.ENVELOPE); folder.fetch(msgs, fp); for (int i = 0; i < msgs.length; i++) { System.out.println("--------------------------"); System.out.println("MESSAGE #" + (i + 1) + ":"); dumpPart(msgs[i]); } folder.close(false); store.close(); } catch (Exception ex) { System.out.println("Oops, got exception! " + ex.getMessage()); ex.printStackTrace(); } System.exit(1); }
From source file:Main.java
private static long currentTime() { Calendar time = Calendar.getInstance(); time.add(Calendar.MILLISECOND, -time.getTimeZone().getOffset(time.getTimeInMillis())); return time.getTime().getTime(); }