List of usage examples for java.util Calendar YEAR
int YEAR
To view the source code for java.util Calendar YEAR.
Click Source Link
get
and set
indicating the year. From source file:Util.java
public static int getYearFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from ww w. j a v a2s . c o m return calendar.get(Calendar.YEAR); }
From source file:Main.java
public static int[] splitDate(Calendar calendar) { return new int[] { calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND) }; }
From source file:Main.java
public static String getTimeStamp(long l) { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(l);//from ww w. j a v a 2 s . c om return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "." + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4) + " " + makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + makeTimeString(cal.get(Calendar.MINUTE), 2) + ":" + makeTimeString(cal.get(Calendar.SECOND), 2); }
From source file:Main.java
public static String getTimeStampDDMMYYYY(long l) { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(l);/* w w w . java2 s . c o m*/ return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "." + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4); }
From source file:Main.java
@SuppressLint("NewApi") public static KeyPair generateRsaPairWithGenerator(Context ctx, String alais) throws InvalidAlgorithmParameterException, NoSuchProviderException, NoSuchAlgorithmException { Calendar notBefore = Calendar.getInstance(); Calendar notAfter = Calendar.getInstance(); notAfter.add(1, Calendar.YEAR); KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(ctx).setAlias(alais) .setSubject(new X500Principal(String.format("CN=%s, OU=%s", alais, ctx.getPackageName()))) .setSerialNumber(BigInteger.ONE).setStartDate(notBefore.getTime()).setEndDate(notAfter.getTime()) .build();//from ww w . j av a 2s .co m KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore"); kpGenerator.initialize(spec); KeyPair kp = kpGenerator.generateKeyPair(); return kp; }
From source file:Main.java
public static boolean hasYearPassed(int year) { int normalized = normalizeYear(year); Calendar now = Calendar.getInstance(); return normalized < now.get(Calendar.YEAR); }
From source file:Main.java
static void setDate(Calendar cal, int month, int date) { cal.clear();/* w w w.ja va 2 s . c o m*/ cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR)); cal.set(Calendar.MONTH, month); cal.set(Calendar.DATE, date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); }
From source file:Main.java
public static XMLGregorianCalendar convertDate(Date date) { try {/* ww w .j a v a 2s. com*/ Calendar c = new GregorianCalendar(); c.setTime(date); XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(); xmlGregorianCalendar.setDay(c.get(Calendar.DAY_OF_MONTH)); xmlGregorianCalendar.setMonth(c.get(Calendar.MONTH)); xmlGregorianCalendar.setYear(c.get(Calendar.YEAR)); return xmlGregorianCalendar; } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * @param date/* w w w . j a v a2 s . c o m*/ * @return */ public static String formatToYesterdayOrToday(Date date) { Calendar today = Calendar.getInstance(); Calendar yesterday = Calendar.getInstance(); yesterday.add(Calendar.DATE, -1); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm"); if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { return "Today, " + timeFormatter.format(date); } else if (calendar.get(Calendar.YEAR) == yesterday.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == yesterday.get(Calendar.DAY_OF_YEAR)) { return "Yesterday, " + timeFormatter.format(date); } else { return DateFormat.format("MMM dd, ", date).toString() + timeFormatter.format(date); } }
From source file:Main.java
public static Date translateDate(String str) { Date date = null;//from w ww. j ava 2 s . co m try { date = sdf1.parse(str); date = sdf11.parse(Calendar.getInstance().get(Calendar.YEAR) + "/" + str); } catch (Exception e) { date = null; } if (date == null) { try { date = sdf2.parse(str); } catch (Exception e) { date = null; } } return date; }