List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:fr.dutra.confluence2wordpress.wp.WordpressClient.java
/** * Date values are received with no time zone information; * Wordpress assumes they are in UTC./*from w ww . ja v a2 s . c o m*/ * Hence the need to convert from a fake date bearing the correct information, * but in a wrong time zone. * @param date * @return */ private Date convertFromNaiveUTC(Date date) { TimeZone zone = TimeZone.getDefault(); long time = date.getTime(); return new Date(time + zone.getOffset(time)); }
From source file:com.redhat.rhn.frontend.action.errata.ErrataSearchAction.java
private String getDateString(Date date) { Calendar cal = Calendar.getInstance(TimeZone.getDefault()); cal.setTime(date);//from ww w . j a v a 2 s . c o m String dateFmt = "yyyy-MM-dd HH:mm:ss"; java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(dateFmt); sdf.setTimeZone(TimeZone.getDefault()); String currentTime = sdf.format(cal.getTime()); return currentTime; }
From source file:com.samknows.measurement.AppSettings.java
public Map<String, String> getJSONExtra() { Map<String, String> ret = new HashMap<String, String>(); if (!anonymous) { ret.put(JSON_UNIT_ID, getUnitId()); }/*from w ww .ja va 2s. co m*/ ret.put(JSON_APP_VERSION_NAME, app_version_name); ret.put(JSON_APP_VERSION_CODE, app_version_code); ScheduleConfig config = CachingStorage.getInstance().loadScheduleConfig(); if (config != null) { ret.put(JSON_SCHEDULE_CONFIG_VERSION, config.version); } else { ret.put(JSON_SCHEDULE_CONFIG_VERSION, "no_schedule_config"); } long time = System.currentTimeMillis(); ret.put(JSON_TIMESTAMP, (time / 1000) + ""); ret.put(JSON_DATETIME, new java.util.Date(time).toString()); ret.put(JSON_TIMEZONE, TimeUtils.millisToHours(TimeZone.getDefault().getRawOffset()) + ""); if (enterprise_id != null) { ret.put(JSON_ENTERPRISE_ID, enterprise_id); } String user_self_id = PreferenceManager.getDefaultSharedPreferences(ctx) .getString(Constants.PREF_USER_SELF_ID, null); if (user_self_id != null) { ret.put(JSON_USER_SELF_ID, user_self_id); } TelephonyManager manager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); String simOperatorCode = ""; if (manager != null) { simOperatorCode = manager.getSimOperator(); } ret.put(JSON_SIMOPERATORCODE, simOperatorCode); return ret; }
From source file:com.jdom.get.stuff.done.android.AndroidSyncStrategy.java
private Task createRemoteTask(Tasks service, ApplicationDao dao, Task localTask, Map<String, String> listNameToRemoteIdentifier) throws IOException { com.google.api.services.tasks.model.Task newGoogleTask = new com.google.api.services.tasks.model.Task(); newGoogleTask.setTitle(localTask.getName()); newGoogleTask.setDeleted(localTask.isDeleted()); newGoogleTask.setStatus(/*from w ww . j a v a 2 s. c o m*/ localTask.isCompleted() ? Constants.GOOGLE_COMPLETED_STRING : Constants.GOOGLE_INCOMPLETE_STRING); newGoogleTask.setNotes(localTask.getDescription()); long time = localTask.getDueDate().getTime(); time -= TimeZone.getDefault().getOffset(time); newGoogleTask.setDue(new DateTime(false, time, 0)); String listName = localTask.getListName(); String remoteId = listNameToRemoteIdentifier.get(listName); if (Constants.DEFAULT_LIST.equals(listName)) { remoteId = Constants.GOOGLE_DEFAULT_LIST_REMOTE_ID; } com.google.api.services.tasks.model.Task created = service.tasks().insert(remoteId, newGoogleTask) .execute(); com.jdom.get.stuff.done.domain.Task updated = localTask.clone(); localTask.setRemoteIdentifier(created.getId()); updated.setRemoteIdentifier(created.getId()); dao.updateTask(localTask, updated); return updated; }
From source file:com.cm.android.beercellar.ui.ImageDetailFragment.java
@Override public void onImageDeleted(boolean success) { //getActivity().getSupportFragmentManager().popBackStack(); mProgressBar.setVisibility(View.GONE); // Do the real work in an async task, because we need to use the network anyway new android.os.AsyncTask<Object, Void, Void>() { @Override/*from w w w .j av a2s . c o m*/ protected Void doInBackground(Object... params) { long rowId = (Long) params[0]; try { HttpTransport httpTransport = new NetHttpTransport(); HttpRequestFactory requestFactory = httpTransport.createRequestFactory(new MyInitializer()); GenericUrl genericUrl = new GenericUrl(Configuration.CONTENTS_URL + "/" + rowId + "/" + System.currentTimeMillis() + "/" + TimeZone.getDefault().getRawOffset()); HttpResponse httpPostResponse = null; try { httpPostResponse = requestFactory.buildDeleteRequest(genericUrl).execute(); Log.i(sTag, "HTTP STATUS:: " + httpPostResponse.getStatusCode()); } finally { httpPostResponse.disconnect(); } } catch (Throwable e) { Log.e(sTag, "error: " + ((e.getMessage() != null) ? e.getMessage().replace(" ", "_") : ""), e); } return null; } }.execute(mRowId); getActivity().finish(); }
From source file:com.layer8apps.CalendarHandler.java
/************ * PURPOSE: Adds the parsed out events to the calendar * ARGUMENTS: NULL/*from w w w . jav a 2s .c o m*/ * RETURNS: VOID * AUTHOR: Devin Collins <agent14709@gmail.com>, Bobby Ore <bob1987@gmail.com> *************/ private int addDays() { ArrayList<Shift> shifts = buildShifts(); try { // deleteOldEvents(); Preferences pf = new Preferences(this); // Get our stored notification time int notification = pf.getNotification(); // Convert the stored time into minutes switch (notification) { case 0: { notification = 0; break; } case 1: { notification = 5; break; } case 2: { notification = 15; break; } case 3: { notification = 30; break; } case 4: { notification = 60; break; } case 5: { notification = 120; break; } case 6: { notification = 180; break; } } shifts = checkForDuplicates(shifts); if (shifts.size() == 0) { return 0; } TimeZone zone = TimeZone.getDefault(); for (Shift shift : shifts) { /************ * ContentResolver and ContentValues are what we use to add * our calendar events to the device *************/ ContentResolver cr = this.getContentResolver(); ContentValues cv = new ContentValues(); /************ * Here we create our calendar event based on the version code *************/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { cv.put(CalendarContract.Events.CALENDAR_ID, calID); cv.put(CalendarContract.Events.DESCRIPTION, shift.getDepartment()); cv.put(CalendarContract.Events.DTEND, shift.getEndDate().getTimeInMillis()); cv.put(CalendarContract.Events.DTSTART, shift.getStartDate().getTimeInMillis()); cv.put(CalendarContract.Events.EVENT_LOCATION, shift.getAddress()); cv.put(CalendarContract.Events.EVENT_TIMEZONE, zone.getID()); cv.put(CalendarContract.Events.HAS_ALARM, (notification == 0) ? 0 : 1); cv.put(CalendarContract.Events.TITLE, shift.getTitle()); } else { cv.put("calendar_id", calID); cv.put("description", shift.getDepartment()); cv.put("dtend", shift.getEndDate().getTimeInMillis()); cv.put("dtstart", shift.getStartDate().getTimeInMillis()); cv.put("eventLocation", shift.getAddress()); cv.put("eventTimezone", zone.getID()); cv.put("title", shift.getTitle()); cv.put("hasAlarm", (notification <= 0) ? 0 : 1); } /************ * Add our events to the calendar based on the Uri we get *************/ Uri uri = cr.insert(getEventsUri(), cv); if (uri == null) { continue; } // Get the ID of the calendar event long eventID = Long.parseLong(uri.getLastPathSegment()); pf.saveShift(String.valueOf(eventID)); /************ * If we retrieved a Uri for the event, try to add the reminder *************/ if (notification > 0) { /************ * Build our reminder based on version code *************/ ContentValues reminders = new ContentValues(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { reminders.put(CalendarContract.Reminders.EVENT_ID, eventID); reminders.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT); reminders.put(CalendarContract.Reminders.MINUTES, notification); } else { reminders.put("event_id", eventID); reminders.put("method", 1); reminders.put("minutes", notification); } // Add the reminder to the system cr.insert(getRemindersUri(), reminders); } } } catch (Exception e) { showError( "Could not create calendar events on calendar, please make sure you have a calendar application on your device"); return -1; } return shifts.size(); }
From source file:com.cttapp.bby.mytlc.layer8apps.CalendarHandler.java
/************ * PURPOSE: Adds the parsed out events to the calendar * ARGUMENTS: NULL// w w w. j a v a2 s . com * RETURNS: VOID * AUTHOR: Devin Collins <agent14709@gmail.com>, Bobby Ore <bob1987@gmail.com> *************/ private int addDays() { ArrayList<Shift> shifts = buildShifts(); try { // deleteOldEvents(); Preferences pf = new Preferences(this); // Get our stored notification time int notification = pf.getNotification(); // Convert the stored time into minutes switch (notification) { case 0: { notification = 0; break; } case 1: { notification = 5; break; } case 2: { notification = 15; break; } case 3: { notification = 30; break; } case 4: { notification = 60; break; } case 5: { notification = 120; break; } case 6: { notification = 180; break; } } createJSONArray(shifts); shifts = checkForDuplicates(shifts); if (shifts.size() == 0) { return 0; } TimeZone zone = TimeZone.getDefault(); for (Shift shift : shifts) { /************ * ContentResolver and ContentValues are what we use to add * our calendar events to the device *************/ ContentResolver cr = this.getContentResolver(); ContentValues cv = new ContentValues(); /************ * Here we create our calendar event based on the version code *************/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { cv.put(CalendarContract.Events.CALENDAR_ID, calID); cv.put(CalendarContract.Events.DESCRIPTION, shift.getDepartment()); cv.put(CalendarContract.Events.DTEND, shift.getEndDate().getTimeInMillis()); cv.put(CalendarContract.Events.DTSTART, shift.getStartDate().getTimeInMillis()); cv.put(CalendarContract.Events.EVENT_LOCATION, shift.getAddress()); cv.put(CalendarContract.Events.EVENT_TIMEZONE, zone.getID()); cv.put(CalendarContract.Events.HAS_ALARM, (notification == 0) ? 0 : 1); cv.put(CalendarContract.Events.TITLE, shift.getTitle()); } else { cv.put("calendar_id", calID); cv.put("description", shift.getDepartment()); cv.put("dtend", shift.getEndDate().getTimeInMillis()); cv.put("dtstart", shift.getStartDate().getTimeInMillis()); cv.put("eventLocation", shift.getAddress()); cv.put("eventTimezone", zone.getID()); cv.put("title", shift.getTitle()); cv.put("hasAlarm", (notification <= 0) ? 0 : 1); } /************ * Add our events to the calendar based on the Uri we get *************/ Uri uri = cr.insert(getEventsUri(), cv); if (uri == null) { continue; } // Get the ID of the calendar event long eventID = Long.parseLong(uri.getLastPathSegment()); pf.saveShift(String.valueOf(eventID)); /************ * If we retrieved a Uri for the event, try to add the reminder *************/ if (notification > 0) { /************ * Build our reminder based on version code *************/ ContentValues reminders = new ContentValues(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { reminders.put(CalendarContract.Reminders.EVENT_ID, eventID); reminders.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT); reminders.put(CalendarContract.Reminders.MINUTES, notification); } else { reminders.put("event_id", eventID); reminders.put("method", 1); reminders.put("minutes", notification); } // Add the reminder to the system cr.insert(getRemindersUri(), reminders); } } } catch (Exception e) { showError( "Could not create calendar events on calendar, please make sure you have a calendar application on your device"); return -1; } return shifts.size(); }
From source file:com.funambol.json.gui.GuiServlet.java
private String doAdd(HttpServletRequest request) throws Exception { String group = getRequestData(request, GROUP, true); String step = getRequestData(request, STEP, true); if (PREPARE.equals(step)) { return showAddPage(group, "Put your Json object here"); } else if (COMMIT.equals(step)) { Repository rep = new Repository((String) request.getSession().getAttribute("username"), TimeZone.getDefault(), "UTF-8"); if (rep == null) { throw new Exception("No repository found for group [" + group + "]."); }/*from ww w.j a va2 s . co m*/ String jsonContent = getRequestData(request, JSONCONTENT); rep.addItem(group, new FakeJsonItem(jsonContent, Util.getSince(request))); return operationExecuted(ADD, request); } throw new Exception("Invalid step [" + step + "] for action [Add]."); }
From source file:com.funambol.json.gui.GuiServlet.java
private String doDelete(HttpServletRequest request) throws Exception { String group = getRequestData(request, GROUP, true); String key = getRequestData(request, KEY, true); Repository rep = new Repository((String) request.getSession().getAttribute("username"), TimeZone.getDefault(), "UTF-8"); rep.delete(group, key);//ww w .jav a 2s . c om return operationExecuted(DELETE, request); }
From source file:Dates.java
/** * Returns the current time zone; never null. This is the time zone that every * other objects shall use, unless they have special consideration. * //from w ww .j a v a 2 s .c o m * <p> * Default: If {@link #setThreadLocal} was called with non-null, the value is * returned. Otherwise, TimeZone.getDefault() is returned, */ public static final TimeZone getCurrent() { final TimeZone l = (TimeZone) _thdTZone.get(); return l != null ? l : TimeZone.getDefault(); }