Example usage for java.util Calendar getTime

List of usage examples for java.util Calendar getTime

Introduction

In this page you can find the example usage for java.util Calendar getTime.

Prototype

public final Date getTime() 

Source Link

Document

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

Usage

From source file:Main.java

public static String getDateFormatString(String format) {
    Calendar c = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat(format, Locale.getDefault()); //called without pattern
    return df.format(c.getTime());
}

From source file:Main.java

public static String getScheduleFormattedDate(String date) {
    java.util.Calendar calendar = getCalendarFromStringDate(date);
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

    return format.format(calendar.getTime());
}

From source file:org.jfree.chart.demo.GanttDemo3.java

private static Date date(int i, int j, int k) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(k, j, i);//from w  w  w.  j a va2s. c  om
    Date date1 = calendar.getTime();
    return date1;
}

From source file:Main.java

public static String getCurrentTime() {
    Calendar currentTime = Calendar.getInstance();
    SimpleDateFormat dateformat = new SimpleDateFormat("HH:mm", Locale.CHINA);
    String timeLableStr = dateformat.format(currentTime.getTime());

    return timeLableStr;
}

From source file:Main.java

public static String GetPostingTime(long milliseconds) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(milliseconds);//from  ww  w.j  ava 2s  .  c  om
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
    return sdf.format(cal.getTime());
}

From source file:Main.java

/**
 * Convert the given Julian Day to Gregorian Date (in UT time zone).
 * Based on the formula given in the Explanitory Supplement to the
 * Astronomical Almanac, pg 604.// w  w  w  .ja  v a  2 s.  c o m
 */
public static Date calculateGregorianDate(double jd) {
    int l = (int) jd + 68569;
    int n = (4 * l) / 146097;
    l = l - (146097 * n + 3) / 4;
    int i = (4000 * (l + 1)) / 1461001;
    l = l - (1461 * i) / 4 + 31;
    int j = (80 * l) / 2447;
    int d = l - (2447 * j) / 80;
    l = j / 11;
    int m = j + 2 - 12 * l;
    int y = 100 * (n - 49) + i + l;

    double fraction = jd - Math.floor(jd);
    double dHours = fraction * 24.0;
    int hours = (int) dHours;
    double dMinutes = (dHours - hours) * 60.0;
    int minutes = (int) dMinutes;
    int seconds = (int) ((dMinutes - minutes) * 60.0);

    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UT"));
    cal.set(y, m - 1, d, hours + 12, minutes, seconds);
    return cal.getTime();
}

From source file:com.streamreduce.util.CAGenerator.java

public static X509Certificate generateCACert(KeyPair keyPair) throws Exception {
    Date startDate = new Date(System.currentTimeMillis()); // time from which certificate is valid
    Calendar expiry = Calendar.getInstance();
    expiry.add(Calendar.DAY_OF_YEAR, 1000 * 365);
    Date expiryDate = expiry.getTime(); // time after which certificate is not valid
    BigInteger serialNumber = new BigInteger(Long.toString(System.currentTimeMillis())); // serial number for certificate

    X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
    X500Principal dnName = new X500Principal("CN=Nodeable Client");

    certGen.setSerialNumber(serialNumber);
    certGen.setIssuerDN(dnName);/*from   w ww  .j  a va 2 s .  c o  m*/
    certGen.setNotBefore(startDate);
    certGen.setNotAfter(expiryDate);
    certGen.setSubjectDN(dnName);
    certGen.setPublicKey(keyPair.getPublic());
    certGen.setSignatureAlgorithm("MD5withRSA");

    certGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false,
            new AuthorityKeyIdentifierStructure(keyPair.getPublic()));
    certGen.addExtension(X509Extensions.SubjectKeyIdentifier, false,
            new SubjectKeyIdentifierStructure(keyPair.getPublic()));

    return certGen.generate(keyPair.getPrivate()); // note: private key of CA
}

From source file:Main.java

public static Date trimSeconds(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*w w  w  .j a  va 2s . c o m*/
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.set(Calendar.SECOND, 0);
    return calendar.getTime();
}

From source file:Main.java

public static String getTime(int laterTime) {
    Calendar calendar = Calendar.getInstance();

    if (laterTime != 0)
        calendar.add(Calendar.HOUR_OF_DAY, 1);

    return new SimpleDateFormat("hh:mm a").format(calendar.getTime());
}

From source file:Main.java

public static Date toTimeZone(Date date, TimeZone source, TimeZone target) {
    Calendar cal1 = Calendar.getInstance(source);
    cal1.setTime(date);//from   ww  w  .j  a  v  a2  s  .co  m

    int[] dateSplit = splitDate(date);

    Calendar cal2 = Calendar.getInstance(target);
    cal2.set(dateSplit[0], dateSplit[1], dateSplit[2], dateSplit[3], dateSplit[4], dateSplit[5]);
    return cal2.getTime();
}