List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:Main.java
public static void IcsMakeNewCalendarEntry(String title, String description, String location, long startTime, long endTime, int allDay, int hasAlarm, int calendarId, int selectedReminderValue) { ContentResolver cr = activityObj.getContentResolver(); ContentValues values = new ContentValues(); values.put(Events.DTSTART, startTime); values.put(Events.DTEND, endTime);//from w w w .j a va2s . co m values.put(Events.TITLE, title); values.put(Events.DESCRIPTION, description); values.put(Events.CALENDAR_ID, calendarId); if (allDay == 1) { values.put(Events.ALL_DAY, true); } if (hasAlarm == 1) { values.put(Events.HAS_ALARM, true); } //Get current timezone values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID()); Log.i(DEBUG_TAG, "Timezone retrieved=>" + TimeZone.getDefault().getID()); Uri uri = cr.insert(Events.CONTENT_URI, values); Log.i(DEBUG_TAG, "Uri returned=>" + uri.toString()); // get the event ID that is the last element in the Uri long eventID = Long.parseLong(uri.getLastPathSegment()); if (hasAlarm == 1) { ContentValues reminders = new ContentValues(); reminders.put(Reminders.EVENT_ID, eventID); reminders.put(Reminders.METHOD, Reminders.METHOD_ALERT); reminders.put(Reminders.MINUTES, selectedReminderValue); Uri uri2 = cr.insert(Reminders.CONTENT_URI, reminders); } }
From source file:Main.java
/** * Try to parse input with SimpleDateFormat * * @param input input./*from w w w . j a v a 2 s . com*/ * @param format SimpleDateFormat * @param setYear1700 When true the age will be not displayed in brackets * @param locale locale. * @return Date object if successful, otherwise null */ private static Date parseStringWithSimpleDateFormat(String input, String format, boolean setYear1700, Locale locale) { SimpleDateFormat dateFormat = new SimpleDateFormat(format, locale); dateFormat.setTimeZone(TimeZone.getDefault()); try { Date parsedDate = dateFormat.parse(input); /* * Because no year is defined in address book, set year to 1700 * * When year < 1800, the age will be not displayed in brackets */ if (setYear1700) { Calendar cal = Calendar.getInstance(); cal.setTime(parsedDate); cal.set(Calendar.YEAR, 1700); } return parsedDate; } catch (ParseException ignored) { return null; } }
From source file:Main.java
public static String getLocalTimeString(String strGMTTime) { String strLocalTime = null;/* w w w. j ava2 s .c o m*/ try { GMTTimeFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); Date date = GMTTimeFormatter.parse(strGMTTime); LocalTimeFormatter.setTimeZone(TimeZone.getDefault()); strLocalTime = LocalTimeFormatter.format(date); } catch (ParseException e) { e.printStackTrace(); } return strLocalTime; }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); res.setHeader("Content-Language", "es"); Locale locale = new Locale("es", ""); DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); fmt.setTimeZone(TimeZone.getDefault()); out.println("En Espa\u00f1ol:"); out.println("\u00a1Hola Mundo!"); out.println(fmt.format(new Date())); }
From source file:Main.java
public static Calendar dateToCalendar(String strYear, String strMonth, String strDay, boolean b) { int year, month, day; try {/*w ww . j a v a 2 s.c o m*/ year = Integer.parseInt(strYear); month = Integer.parseInt(strMonth) - 1; day = Integer.parseInt(strDay); } catch (StringIndexOutOfBoundsException e) { return null; } catch (NumberFormatException e) { return null; } Calendar cal = Calendar.getInstance(TimeZone.getDefault()); cal.setLenient(b); cal.set(year, month, day, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); return cal; }
From source file:Main.java
public static String getLocalTimeString(long millisecond) { LocalTimeFormatter.setTimeZone(TimeZone.getDefault()); String strLocalTime = LocalTimeFormatter.format(millisecond); return strLocalTime; }
From source file:DateUtils.java
public static final String formatDate(Date dt, String format) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(dt);/*from w w w . j a v a 2 s . c o m*/ java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format); sdf.setTimeZone(TimeZone.getDefault()); return (sdf.format(cal.getTime())); }
From source file:io.horizondb.model.core.util.TimeUtils.java
/** * Parses the specified <code>String</code> representing a date/time. * <p>The supported patterns are: 'yyyy-MM-dd', 'yyyy-MM-dd HH:mm:ss' and * 'yyyy-MM-dd HH:mm:ss.SSS'.</p>/* w w w . j a v a2 s.c om*/ * * @param dateTime the <code>String</code> representing a date/time. * @return the time in millisecond since epoch */ public static long parseDateTime(String dateTime) { return parseDateTime(TimeZone.getDefault(), dateTime); }
From source file:Main.java
/** * Returns a ISO 8601 representation of the given date, which is * in an unknown timezone. This method is thread safe and non-blocking. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-495">TIKA-495</a> * @param date given date/*from w ww . j a v a 2 s . com*/ * @return ISO 8601 date string, without timezone details */ public static String formatDateUnknownTimezone(Date date) { // Create the Calendar object in the system timezone Calendar calendar = GregorianCalendar.getInstance(TimeZone.getDefault(), Locale.US); calendar.setTime(date); // Have it formatted String formatted = formatDate(calendar); // Strip the timezone details before returning return formatted.substring(0, formatted.length() - 1); }
From source file:org.jfree.chart.demo.QuarterDateFormatDemo.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date", "Price Per Unit", xydataset, true, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); PeriodAxis periodaxis = new PeriodAxis("Quarter", new Quarter(), new Quarter()); periodaxis.setAutoRangeTimePeriodClass(org.jfree.data.time.Quarter.class); PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[1]; aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Quarter.class, new QuarterDateFormat(TimeZone.getDefault(), QuarterDateFormat.ROMAN_QUARTERS)); periodaxis.setLabelInfo(aperiodaxislabelinfo); xyplot.setDomainAxis(periodaxis);//from ww w .j a v a 2s. co m 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); } return jfreechart; }