List of usage examples for java.util Calendar AM_PM
int AM_PM
To view the source code for java.util Calendar AM_PM.
Click Source Link
get
and set
indicating whether the HOUR
is before or after noon. From source file:Main.java
public static void main(String[] args) { Calendar cal = new GregorianCalendar(); System.out.println(cal.getTime()); cal.set(Calendar.AM_PM, Calendar.AM); System.out.println(cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = new GregorianCalendar(); System.out.println(cal.getTime()); cal.set(Calendar.AM_PM, Calendar.PM); System.out.println(cal.getTime()); }
From source file:CalendarManipulation.java
public static void main(String s[]) { Calendar cal = Calendar.getInstance(); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM); System.out.println(df.format(cal.getTime())); cal.add(Calendar.AM_PM, 1); System.out.println(df.format(cal.getTime())); }
From source file:Main.java
public static void main(String[] argv) throws Exception { // Get the current time in Hong Kong Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("Hongkong")); int hour12 = cal.get(Calendar.HOUR); // 0..11 int minutes = cal.get(Calendar.MINUTE); // 0..59 int seconds = cal.get(Calendar.SECOND); // 0..59 boolean am = cal.get(Calendar.AM_PM) == Calendar.AM; // Get the current hour-of-day at GMT cal.setTimeZone(TimeZone.getTimeZone("GMT")); int hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23 // Get the current local hour-of-day cal.setTimeZone(TimeZone.getDefault()); hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23 }
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:Main.java
public static void main(String[] argv) throws Exception { Calendar local = Calendar.getInstance(); Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan")); japanCal.setTimeInMillis(local.getTimeInMillis()); int hour = japanCal.get(Calendar.HOUR); // 3 int minutes = japanCal.get(Calendar.MINUTE); // 0 int seconds = japanCal.get(Calendar.SECOND); // 0 boolean am = japanCal.get(Calendar.AM_PM) == Calendar.AM; // true }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan")); japanCal.set(Calendar.HOUR_OF_DAY, 10); // 0..23 japanCal.set(Calendar.MINUTE, 0); japanCal.set(Calendar.SECOND, 0); Calendar local = new GregorianCalendar(); local.setTimeInMillis(japanCal.getTimeInMillis()); int hour = local.get(Calendar.HOUR); // 5 int minutes = local.get(Calendar.MINUTE); // 0 int seconds = local.get(Calendar.SECOND); // 0 boolean am = local.get(Calendar.AM_PM) == Calendar.AM; // false }
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:DayWeek.java
public static void main(String[] av) { //+/*from w w w .j a v a 2s .c om*/ Calendar c = Calendar.getInstance(); // today System.out.println("Year: " + c.get(Calendar.YEAR)); System.out.println("Month: " + c.get(Calendar.MONTH)); System.out.println("Day: " + c.get(Calendar.DAY_OF_MONTH)); System.out.println("Day of week = " + c.get(Calendar.DAY_OF_WEEK)); System.out.println("Day of year = " + c.get(Calendar.DAY_OF_YEAR)); System.out.println("Week in Year: " + c.get(Calendar.WEEK_OF_YEAR)); System.out.println("Week in Month: " + c.get(Calendar.WEEK_OF_MONTH)); System.out.println("Day of Week in Month: " + c.get(Calendar.DAY_OF_WEEK_IN_MONTH)); System.out.println("Hour: " + c.get(Calendar.HOUR)); System.out.println("AM or PM: " + c.get(Calendar.AM_PM)); System.out.println("Hour (24-hour clock): " + c.get(Calendar.HOUR_OF_DAY)); System.out.println("Minute: " + c.get(Calendar.MINUTE)); System.out.println("Second: " + c.get(Calendar.SECOND)); //- }
From source file:search.java
public static void main(String argv[]) { int optind;// w w w . j a v a 2 s.c o m 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); }