List of usage examples for android.text.format Time getCurrentTimezone
public static String getCurrentTimezone()
From source file:uk.org.openseizuredetector.OsdUtil.java
/** * Write data to SD card - writes to data log file unless alarm=true, * in which case writes to alarm log file. *///from w ww . j a v a2 s . c o m public void writeToLogFile(String fname, String msgStr) { Log.v(TAG, "writeToLogFile(" + fname + "," + msgStr + ")"); //showToast("Logging " + msgStr); Time tnow = new Time(Time.getCurrentTimezone()); tnow.setToNow(); String dateStr = tnow.format("%Y-%m-%d"); fname = fname + "_" + dateStr + ".txt"; // Open output directory on SD Card. if (isExternalStorageWritable()) { try { FileWriter of = new FileWriter(getDataStorageDir().toString() + "/" + fname, true); if (msgStr != null) { String dateTimeStr = tnow.format("%Y-%m-%d %H:%M:%S"); Log.v(TAG, "writing msgStr"); of.append(dateTimeStr + ", " + tnow.toMillis(true) + ", " + msgStr + "<br/>\n"); } of.close(); } catch (Exception ex) { Log.e(TAG, "writeToLogFile - error " + ex.toString()); showToast("ERROR Writing to Log File"); } } else { Log.e(TAG, "ERROR - Can not Write to External Folder"); } }
From source file:ti.android.ble.devicemonitor.ServiceView.java
private String timeNowStr() { Time now = new Time(Time.getCurrentTimezone()); now.setToNow();/* w w w . ja v a 2s . c om*/ return now.format("%k:%M:%S") + ": "; }
From source file:io.doist.datetimepicker.date.SimpleMonthView.java
/** * Sets all the parameters for displaying this week. Parameters have a default value and * will only update if a new value is included, except for focus month, which will always * default to no focus month if no value is passed in. The only required parameter is the * week start.// w w w . j av a2s . com * * @param selectedDay the selected day of the month, or -1 for no selection. * @param month the month. * @param year the year. * @param weekStart which day the week should start on. {@link Calendar#SUNDAY} through * {@link Calendar#SATURDAY}. * @param enabledDayStart the first enabled day. * @param enabledDayEnd the last enabled day. */ void setMonthParams(int selectedDay, int month, int year, int weekStart, int enabledDayStart, int enabledDayEnd) { if (mRowHeight < MIN_HEIGHT) { mRowHeight = MIN_HEIGHT; } mSelectedDay = selectedDay; if (isValidMonth(month)) { mMonth = month; } mYear = year; // Figure out what day today is final Time today = new Time(Time.getCurrentTimezone()); today.setToNow(); mHasToday = false; mToday = -1; mCalendar.set(Calendar.MONTH, mMonth); mCalendar.set(Calendar.YEAR, mYear); mCalendar.set(Calendar.DAY_OF_MONTH, 1); mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK); if (isValidDayOfWeek(weekStart)) { mWeekStart = weekStart; } else { mWeekStart = mCalendar.getFirstDayOfWeek(); } if (enabledDayStart > 0 && enabledDayEnd < 32) { mEnabledDayStart = enabledDayStart; } if (enabledDayEnd > 0 && enabledDayEnd < 32 && enabledDayEnd >= enabledDayStart) { mEnabledDayEnd = enabledDayEnd; } mNumCells = getDaysInMonth(mMonth, mYear); for (int i = 0; i < mNumCells; i++) { final int day = i + 1; if (sameDay(day, today)) { mHasToday = true; mToday = day; } } mNumRows = calculateNumRows(); // Invalidate cached accessibility information. mTouchHelper.invalidateRoot(); }
From source file:org.holoeverywhere.widget.datetimepicker.date.SimpleMonthView.java
/** * Sets all the parameters for displaying this week. The only required * parameter is the week number. Other parameters have a default value and * will only update if a new value is included, except for focus month, * which will always default to no focus month if no value is passed in. See * {@link #VIEW_PARAMS_HEIGHT} for more info on parameters. * * @param params A map of the new parameters, see * {@link #VIEW_PARAMS_HEIGHT} *///from www . j a v a 2s . c o m public void setMonthParams(HashMap<String, Integer> params) { if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) { throw new InvalidParameterException("You must specify the month and year for this view"); } setTag(params); // We keep the current value for any params not present if (params.containsKey(VIEW_PARAMS_HEIGHT)) { mRowHeight = params.get(VIEW_PARAMS_HEIGHT); if (mRowHeight < MIN_HEIGHT) { mRowHeight = MIN_HEIGHT; } } if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) { mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY); } // Allocate space for caching the day numbers and focus values mMonth = params.get(VIEW_PARAMS_MONTH); mYear = params.get(VIEW_PARAMS_YEAR); // Figure out what day today is final Time today = new Time(Time.getCurrentTimezone()); today.setToNow(); mHasToday = false; mToday = -1; mCalendar.set(Calendar.MONTH, mMonth); mCalendar.set(Calendar.YEAR, mYear); mCalendar.set(Calendar.DAY_OF_MONTH, 1); mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK); if (params.containsKey(VIEW_PARAMS_WEEK_START)) { mWeekStart = params.get(VIEW_PARAMS_WEEK_START); } else { mWeekStart = mCalendar.getFirstDayOfWeek(); } mNumCells = DateTimePickerUtils.getDaysInMonth(mMonth, mYear); for (int i = 0; i < mNumCells; i++) { final int day = i + 1; if (sameDay(day, today)) { mHasToday = true; mToday = day; } } mNumRows = calculateNumRows(); // Invalidate cached accessibility information. mNodeProvider.invalidateParent(); }
From source file:app.android.datetimepicker.date.SimpleMonthView.java
/** * Sets all the parameters for displaying this week. The only required * parameter is the week number. Other parameters have a default value and * will only update if a new value is included, except for focus month, * which will always default to no focus month if no value is passed in. See * {@link #VIEW_PARAMS_HEIGHT} for more info on parameters. * * @param params A map of the new parameters, see * {@link #VIEW_PARAMS_HEIGHT} *//* w w w. ja va 2 s . c o m*/ public void setMonthParams(HashMap<String, Integer> params) { if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) { throw new InvalidParameterException("You must specify the month and year for this view"); } setTag(params); // We keep the current value for any params not present if (params.containsKey(VIEW_PARAMS_HEIGHT)) { mRowHeight = params.get(VIEW_PARAMS_HEIGHT); if (mRowHeight < MIN_HEIGHT) { mRowHeight = MIN_HEIGHT; } } if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) { mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY); } // Allocate space for caching the day numbers and focus values mMonth = params.get(VIEW_PARAMS_MONTH); mYear = params.get(VIEW_PARAMS_YEAR); // Figure out what day today is final Time today = new Time(Time.getCurrentTimezone()); today.setToNow(); mHasToday = false; mToday = -1; mCalendar.set(Calendar.MONTH, mMonth); mCalendar.set(Calendar.YEAR, mYear); mCalendar.set(Calendar.DAY_OF_MONTH, 1); mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK); if (params.containsKey(VIEW_PARAMS_WEEK_START)) { mWeekStart = params.get(VIEW_PARAMS_WEEK_START); } else { mWeekStart = mCalendar.getFirstDayOfWeek(); } mNumCells = Utils.getDaysInMonth(mMonth, mYear); for (int i = 0; i < mNumCells; i++) { final int day = i + 1; if (sameDay(day, today)) { mHasToday = true; mToday = day; } } mNumRows = calculateNumRows(); // Invalidate cached accessibility information. mTouchHelper.invalidateRoot(); }
From source file:org.apache.cordova.core.Globalization.java
private JSONObject getDatePattern(JSONArray options) throws GlobalizationError { JSONObject obj = new JSONObject(); try {/*from w ww .j a v a2 s . c om*/ SimpleDateFormat fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getDateFormat(this.cordova.getActivity()); //default user preference for date SimpleDateFormat fmtTime = (SimpleDateFormat) android.text.format.DateFormat .getTimeFormat(this.cordova.getActivity()); //default user preference for time String fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); //default SHORT date/time format. ex. dd/MM/yyyy h:mm a //get Date value + options (if available) if (options.getJSONObject(0).has(OPTIONS)) { //options were included JSONObject innerOptions = options.getJSONObject(0).getJSONObject(OPTIONS); //get formatLength option if (!innerOptions.isNull(FORMATLENGTH)) { String fmtOpt = innerOptions.getString(FORMATLENGTH); if (fmtOpt.equalsIgnoreCase(MEDIUM)) {//medium fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getMediumDateFormat(this.cordova.getActivity()); } else if (fmtOpt.equalsIgnoreCase(LONG) || fmtOpt.equalsIgnoreCase(FULL)) { //long/full fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getLongDateFormat(this.cordova.getActivity()); } } //return pattern type fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); if (!innerOptions.isNull(SELECTOR)) { String selOpt = innerOptions.getString(SELECTOR); if (selOpt.equalsIgnoreCase(DATE)) { fmt = fmtDate.toLocalizedPattern(); } else if (selOpt.equalsIgnoreCase(TIME)) { fmt = fmtTime.toLocalizedPattern(); } } } //TimeZone from users device //TimeZone tz = Calendar.getInstance(Locale.getDefault()).getTimeZone(); //substitute method TimeZone tz = TimeZone.getTimeZone(Time.getCurrentTimezone()); obj.put("pattern", fmt); obj.put("timezone", tz.getDisplayName(tz.inDaylightTime(Calendar.getInstance().getTime()), TimeZone.SHORT)); obj.put("utc_offset", tz.getRawOffset() / 1000); obj.put("dst_offset", tz.getDSTSavings() / 1000); return obj; } catch (Exception ge) { throw new GlobalizationError(GlobalizationError.PATTERN_ERROR); } }
From source file:org.apache.cordova.Globalization.java
private JSONObject getDatePattern(JSONArray options) throws GlobalizationError { JSONObject obj = new JSONObject(); try {/*w ww.j a v a 2 s.com*/ SimpleDateFormat fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getDateFormat(this.cordova.getActivity()); //default user preference for date SimpleDateFormat fmtTime = (SimpleDateFormat) android.text.format.DateFormat .getTimeFormat(this.cordova.getActivity()); //default user preference for time String fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); //default SHORT date/time format. ex. dd/MM/yyyy h:mm a //get Date value + options (if available) boolean test = options.getJSONObject(0).has(OPTIONS); if (options.getJSONObject(0).has(OPTIONS)) { //options were included JSONObject innerOptions = options.getJSONObject(0).getJSONObject(OPTIONS); //get formatLength option if (!innerOptions.isNull(FORMATLENGTH)) { String fmtOpt = innerOptions.getString(FORMATLENGTH); if (fmtOpt.equalsIgnoreCase(MEDIUM)) {//medium fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getMediumDateFormat(this.cordova.getActivity()); } else if (fmtOpt.equalsIgnoreCase(LONG) || fmtOpt.equalsIgnoreCase(FULL)) { //long/full fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getLongDateFormat(this.cordova.getActivity()); } } //return pattern type fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); if (!innerOptions.isNull(SELECTOR)) { String selOpt = innerOptions.getString(SELECTOR); if (selOpt.equalsIgnoreCase(DATE)) { fmt = fmtDate.toLocalizedPattern(); } else if (selOpt.equalsIgnoreCase(TIME)) { fmt = fmtTime.toLocalizedPattern(); } } } //TimeZone from users device //TimeZone tz = Calendar.getInstance(Locale.getDefault()).getTimeZone(); //substitute method TimeZone tz = TimeZone.getTimeZone(Time.getCurrentTimezone()); obj.put("pattern", fmt); obj.put("timezone", tz.getDisplayName(tz.inDaylightTime(Calendar.getInstance().getTime()), TimeZone.SHORT)); obj.put("utc_offset", tz.getRawOffset() / 1000); obj.put("dst_offset", tz.getDSTSavings() / 1000); return obj; } catch (Exception ge) { throw new GlobalizationError(GlobalizationError.PATTERN_ERROR); } }
From source file:com.intel.RtcPingDownloadTester.java
private void update_conole_writeln(String line) { Time today = new Time(Time.getCurrentTimezone()); today.setToNow();/* w w w . ja v a 2 s.c om*/ if (full_lines >= 10) { full_lines = 0; string_console_text = ""; } full_lines++; string_console_text += today.format("%k:%M:%S") + ": " + line + "\n"; label_console_box.setText(string_console_text); }
From source file:uk.org.openseizuredetector.SdServer.java
/** * Sends SMS Alarms to the telephone numbers specified in mSMSNumbers[] *//*from w ww . j a v a 2 s. c om*/ public void sendSMSAlarm() { if (mSMSAlarm) { Log.v(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers.length + " Numbers"); Time tnow = new Time(Time.getCurrentTimezone()); tnow.setToNow(); String dateStr = tnow.format("%Y-%m-%d %H-%M-%S"); SmsManager sm = SmsManager.getDefault(); for (int i = 0; i < mSMSNumbers.length; i++) { Log.v(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers[i]); sm.sendTextMessage(mSMSNumbers[i], null, mSMSMsgStr + " - " + dateStr, null, null); } } else { Log.v(TAG, "sendSMSAlarm() - SMS Alarms Disabled - not doing anything!"); Toast toast = Toast.makeText(getApplicationContext(), "SMS Alarms Disabled - not doing anything!", Toast.LENGTH_SHORT); toast.show(); } }
From source file:com.android.yijiang.kzx.widget.betterpickers.calendardatepicker.SimpleMonthView.java
/** * Sets all the parameters for displaying this week. The only required parameter is the week number. Other * parameters have a default value and will only update if a new value is included, except for focus month, which * will always default to no focus month if no value is passed in. See {@link #VIEW_PARAMS_HEIGHT} for more info on * parameters.//from w w w .j a v a 2s. c om * * @param params A map of the new parameters, see {@link #VIEW_PARAMS_HEIGHT} * @param tz The time zone this view should reference times in */ public void setMonthParams(HashMap<String, Integer> params) { if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) { throw new InvalidParameterException("You must specify the month and year for this view"); } setTag(params); // We keep the current value for any params not present if (params.containsKey(VIEW_PARAMS_HEIGHT)) { mRowHeight = params.get(VIEW_PARAMS_HEIGHT); if (mRowHeight < MIN_HEIGHT) { mRowHeight = MIN_HEIGHT; } } if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) { mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY); } // Allocate space for caching the day numbers and focus values mMonth = params.get(VIEW_PARAMS_MONTH); mYear = params.get(VIEW_PARAMS_YEAR); // Figure out what day today is final Time today = new Time(Time.getCurrentTimezone()); today.setToNow(); mHasToday = false; mToday = -1; mCalendar.set(Calendar.MONTH, mMonth); mCalendar.set(Calendar.YEAR, mYear); mCalendar.set(Calendar.DAY_OF_MONTH, 1); mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK); if (params.containsKey(VIEW_PARAMS_WEEK_START)) { mWeekStart = params.get(VIEW_PARAMS_WEEK_START); } else { mWeekStart = mCalendar.getFirstDayOfWeek(); } mNumCells = Utils.getDaysInMonth(mMonth, mYear); for (int i = 0; i < mNumCells; i++) { final int day = i + 1; if (sameDay(day, today)) { mHasToday = true; mToday = day; } } mNumRows = calculateNumRows(); // Invalidate cached accessibility information. mNodeProvider.invalidateParent(); }