List of usage examples for java.util Calendar getInstance
public static Calendar getInstance()
From source file:Main.java
public static void main(String[] args) { Date today = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(today);// ww w. j a v a 2 s . co m calendar.add(Calendar.MONTH, 1); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.add(Calendar.DATE, -1); Date lastDayOfMonth = calendar.getTime(); DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); System.out.println("Today : " + sdf.format(today)); System.out.println("Last Day of Month: " + sdf.format(lastDayOfMonth)); }
From source file:Main.java
public static void main(String[] args) { String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; Calendar cal = Calendar.getInstance(); String month = months[cal.get(Calendar.MONTH)]; System.out.println("Month name: " + month); }
From source file:Main.java
public static void main(String[] args) { String[] monthName = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; Calendar cal = Calendar.getInstance(); String month = monthName[cal.get(Calendar.MONTH)]; System.out.println("Month name: " + month); }
From source file:Today.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); cal.set(HOUR_OF_DAY, 0);/*from w w w .j a va2s . co m*/ cal.set(MINUTE, 0); cal.set(SECOND, 0); cal.set(MILLISECOND, 0); System.out.println(cal.getTime()); }
From source file:MainClass.java
public static void main(String args[]) { Formatter fmt = new Formatter(); Calendar cal = Calendar.getInstance(); fmt.format("%tr", cal); System.out.println(fmt);/* w w w .j a v a 2s . c o m*/ fmt = new Formatter(); fmt.format("%tc", cal); System.out.println(fmt); fmt = new Formatter(); fmt.format("%tl:%tM", cal, cal); System.out.println(fmt); fmt = new Formatter(); fmt.format("%tB %tb %tm", cal, cal, cal); System.out.println(fmt); }
From source file:Main.java
public static void main(String[] args) { DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); long now = System.currentTimeMillis(); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(now);//w w w . java 2 s.c om System.out.println(now + " = " + formatter.format(calendar.getTime())); }
From source file:Main.java
public static void main(String[] args) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:00Z"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2015); cal.set(Calendar.MONTH, Calendar.SEPTEMBER); cal.set(Calendar.DATE, 1);/*from w ww . java 2 s .c om*/ cal.set(Calendar.HOUR_OF_DAY, 12); cal.set(Calendar.MINUTE, 15); Date date = cal.getTime(); System.out.println(date); TimeZone tz = TimeZone.getTimeZone("IST"); dateFormat.setTimeZone(tz); String actual = dateFormat.format(date); System.out.println(actual); }
From source file:Main.java
public static void main(String[] args) { Calendar first = Calendar.getInstance(); first.set(2008, Calendar.AUGUST, 1); Calendar second = Calendar.getInstance(); System.out.println(getDifference(first, second, TimeUnit.DAYS) + " day(s) between "); }
From source file:Main.java
public static void main(String[] argv) { Instant instantFromDate = new Date().toInstant(); Instant instantFromCalendar = Calendar.getInstance().toInstant(); System.out.println(instantFromCalendar); ZoneId zoneId = java.util.TimeZone.getDefault().toZoneId(); System.out.println(zoneId);/*www .j a va2 s . c om*/ ZonedDateTime zonedDateTimeFromGregorianCalendar = new GregorianCalendar().toZonedDateTime(); System.out.println(zonedDateTimeFromGregorianCalendar); }
From source file:J2METimeServer.java
public static void main(String[] args) { try {/* ww w.j a v a 2 s .co m*/ Calendar cal = Calendar.getInstance(); DatagramConnection receiver = (DatagramConnection) Connector.open("datagram://"); byte[] buffer = new byte[256]; Datagram dgram = receiver.newDatagram(buffer, buffer.length); for (;;) { dgram.setLength(buffer.length); receiver.receive(dgram); cal.setTime(new Date()); String time = cal.toString(); byte[] dataBytes = time.getBytes(); System.arraycopy(dataBytes, 0, buffer, 0, dataBytes.length); dgram.setLength(dataBytes.length); receiver.send(dgram); } } catch (IOException ex) { System.out.println("IOException: " + ex); } }