Example usage for java.util GregorianCalendar getTime

List of usage examples for java.util GregorianCalendar getTime

Introduction

In this page you can find the example usage for java.util GregorianCalendar 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

/**
 * Convert date from XML GregorianCalendar to String in 'MM/dd/yyyy hh:mm:ss'
 * /*from  ww w  . j a v  a  2  s.  c  o  m*/
 * @param xmlCalendar
 * @return String
 */
public static String XMLGregorianCalendartoString(XMLGregorianCalendar xmlCalendar) {
    GregorianCalendar calendar = xmlCalendar.toGregorianCalendar();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
    return simpleDateFormat.format(calendar.getTime());
}

From source file:DateUtils.java

/**
 * A method to get the current date and time to use in a timestamp
 *
 * @return  a string containing the timestamp
 */// w w w. ja  v  a 2  s.  co  m
public static String getCurrentDateAndTime() {

    GregorianCalendar calendar = new GregorianCalendar();
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

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

}

From source file:Main.java

public static boolean isPastDate(String year, String month, String day) {
    try {/*from   w ww.ja  v a  2 s.  c o  m*/
        GregorianCalendar cal = new GregorianCalendar();
        cal.setLenient(false);
        SimpleDateFormat fmDate = new SimpleDateFormat("yyyyMMdd");
        String today = fmDate.format(cal.getTime());
        cal.clear();
        cal.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day));
        String inputday = fmDate.format(cal.getTime());

        if (inputday.compareTo(today) < 0) {
            return true;
        } else {
            return false;
        }
    } catch (IllegalArgumentException e) {
        return false;
    }
}

From source file:Main.java

/**
 *
 * @return// w w w.j  a v a  2 s .c om
 */
public static String tomorrow() {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(new Date());
    gc.add(GregorianCalendar.DATE, 1);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    return sdf.format(gc.getTime());
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("US$ Treasury Yields", "Date", "Yield",
            xydataset, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    GregorianCalendar gregoriancalendar = new GregorianCalendar(2005, 10, 15);
    xyplot.setDomainAxis(new CustomDateAxis("Date", gregoriancalendar.getTime()));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }//from   w w w . j  a  va 2 s . co m
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    jfreechart.addSubtitle(new TextTitle("November 2005"));
    TextTitle texttitle = new TextTitle("Source: http://www.econstats.com/r/r_am1.htm");
    texttitle.setFont(new Font("Dialog", 0, 9));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:DateUtils.java

public static Date getLastWeek() {
    GregorianCalendar dayBeforeThisWeek = new GregorianCalendar();
    int dayFromMonday = (dayBeforeThisWeek.get(Calendar.DAY_OF_WEEK) + 7 - Calendar.MONDAY) % 7;
    dayBeforeThisWeek.add(Calendar.DATE, -dayFromMonday - 1);
    return dayBeforeThisWeek.getTime();
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("US$ Treasury Yields", "Date", "Yield",
            xydataset, false, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    GregorianCalendar gregoriancalendar = new GregorianCalendar(2005, 10, 15);
    xyplot.setDomainAxis(new CustomDateAxis("Date", gregoriancalendar.getTime()));
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }/*from w w  w .jav a  2  s  . co  m*/
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    jfreechart.addSubtitle(new TextTitle("November 2005"));
    TextTitle texttitle = new TextTitle("Source: http://www.econstats.com/r/r_am1.htm");
    texttitle.setFont(new Font("Dialog", 0, 9));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);
    return jfreechart;
}

From source file:dev.meng.wikipedia.profiler.util.StringUtils.java

public static String formatTimestamp(GregorianCalendar date, String format) {
    SimpleDateFormat formatter = new SimpleDateFormat(format);
    return formatter.format(date.getTime());
}

From source file:net.darkmist.clf.LogParserTest.java

private static Date mkLogTimeAsDate() {
    GregorianCalendar cal = new GregorianCalendar(2007, 5, 5, 8, 9, 10);
    cal.setTimeZone(TimeZone.getTimeZone("GMT-1"));
    return cal.getTime();
}

From source file:Main.java

/**
 * Remove the time of a date value/*  ww  w. j a va  2s . c om*/
 *
 * @param date Date to remove the time part
 * @return A date with its time set to 00:00:00
 */
public static Date removeTime(Date date) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);
    gc.set(Calendar.HOUR_OF_DAY, 0);
    gc.set(Calendar.MINUTE, 0);
    gc.set(Calendar.SECOND, 0);
    gc.set(Calendar.MILLISECOND, 0);
    return gc.getTime();
}