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;
}
}
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);
}
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;
}
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);
}
}
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);
}
Aggregations