Search in sources :

Example 11 with DateFormat

use of java.text.DateFormat in project LogisticsPipes by RS485.

the class RequestMonitorPopup method saveImage.

private void saveImage(BufferedImage bufferedimage) {
    File screenShotsFolder = new File(Minecraft.getMinecraft().mcDataDir, "screenshots");
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
    String s = dateFormat.format(new Date()).toString();
    int i = 1;
    while (true) {
        File canidate = new File(screenShotsFolder, s + (i == 1 ? "" : "_" + i) + ".png");
        if (!canidate.exists()) {
            try {
                ImageIO.write(bufferedimage, "png", canidate);
                Minecraft.getMinecraft().thePlayer.sendChatMessage("Saved tree view as " + canidate.getName());
            } catch (IOException e) {
                e.printStackTrace();
            }
            return;
        }
        ++i;
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) IOException(java.io.IOException) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 12 with DateFormat

use of java.text.DateFormat in project Anki-Android by Ramblurr.

the class TimeChart method drawXLabels.

/**
   * The graphical representation of the labels on the X axis.
   * 
   * @param xLabels the X labels values
   * @param xTextLabelLocations the X text label locations
   * @param canvas the canvas to paint to
   * @param paint the paint to be used for drawing
   * @param left the left value of the labels area
   * @param top the top value of the labels area
   * @param bottom the bottom value of the labels area
   * @param xPixelsPerUnit the amount of pixels per one unit in the chart labels
   * @param minX the minimum value on the X axis in the chart
   * @param maxX the maximum value on the X axis in the chart
   */
@Override
protected void drawXLabels(List<Double> xLabels, Double[] xTextLabelLocations, Canvas canvas, Paint paint, int left, int top, int bottom, double xPixelsPerUnit, double minX, double maxX) {
    int length = xLabels.size();
    if (length > 0) {
        boolean showLabels = mRenderer.isShowLabels();
        boolean showGridY = mRenderer.isShowGridY();
        DateFormat format = getDateFormat(xLabels.get(0), xLabels.get(length - 1));
        for (int i = 0; i < length; i++) {
            long label = Math.round(xLabels.get(i));
            float xLabel = (float) (left + xPixelsPerUnit * (label - minX));
            if (showLabels) {
                paint.setColor(mRenderer.getXLabelsColor());
                canvas.drawLine(xLabel, bottom, xLabel, bottom + mRenderer.getLabelsTextSize() / 3, paint);
                drawText(canvas, format.format(new Date(label)), xLabel, bottom + mRenderer.getLabelsTextSize() * 4 / 3, paint, mRenderer.getXLabelsAngle());
            }
            if (showGridY) {
                paint.setColor(mRenderer.getGridColor());
                canvas.drawLine(xLabel, bottom, xLabel, top, paint);
            }
        }
    }
    drawXTextLabels(xTextLabelLocations, canvas, paint, true, left, top, bottom, xPixelsPerUnit, minX, maxX);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Paint(android.graphics.Paint) Date(java.util.Date)

Example 13 with DateFormat

use of java.text.DateFormat in project Anki-Android by Ramblurr.

the class TimeChart method getDateFormat.

/**
   * Returns the date format pattern to be used, based on the date range.
   * 
   * @param start the start date in milliseconds
   * @param end the end date in milliseconds
   * @return the date format
   */
private DateFormat getDateFormat(double start, double end) {
    if (mDateFormat != null) {
        SimpleDateFormat format = null;
        try {
            format = new SimpleDateFormat(mDateFormat);
            return format;
        } catch (Exception e) {
        // do nothing here
        }
    }
    DateFormat format = SimpleDateFormat.getDateInstance(SimpleDateFormat.MEDIUM);
    double diff = end - start;
    if (diff > DAY && diff < 5 * DAY) {
        format = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);
    } else if (diff < DAY) {
        format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM);
    }
    return format;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 14 with DateFormat

use of java.text.DateFormat in project storymaker by StoryMaker.

the class AppConstants method timestampToMillis.

public static final long timestampToMillis(String ts) throws ParseException {
    //2012:06:12 10:42:04
    try {
        DateFormat df = new SimpleDateFormat("yyyy:MM:dd hh:mm:ss", Locale.getDefault());
        Date d = (Date) df.parse(ts);
        return d.getTime();
    } catch (ParseException e) {
        return Long.parseLong(ts);
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 15 with DateFormat

use of java.text.DateFormat in project NewPipe by TeamNewPipe.

the class Localization method formatDate.

private static String formatDate(String date, Context context) {
    Locale locale = getPreferredLocale(context);
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    Date datum = null;
    try {
        datum = formatter.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
    return df.format(datum);
}
Also used : Locale(java.util.Locale) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

DateFormat (java.text.DateFormat)646 SimpleDateFormat (java.text.SimpleDateFormat)486 Date (java.util.Date)315 ParseException (java.text.ParseException)132 Calendar (java.util.Calendar)78 Test (org.junit.Test)69 ArrayList (java.util.ArrayList)48 IOException (java.io.IOException)43 File (java.io.File)31 HashMap (java.util.HashMap)27 GregorianCalendar (java.util.GregorianCalendar)24 TimeZone (java.util.TimeZone)23 Locale (java.util.Locale)18 Timestamp (java.sql.Timestamp)17 List (java.util.List)14 InputStream (java.io.InputStream)12 DateTime (org.joda.time.DateTime)11 Map (java.util.Map)10 Matcher (java.util.regex.Matcher)8 TestBean (org.springframework.tests.sample.beans.TestBean)8