List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:org.jfree.data.time.junit.DayTest.java
/** * Some checks for the getLastMillisecond() method. *//*w w w. j av a2s . c om*/ public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Day d = new Day(1, 1, 1970); assertEquals(82799999L, d.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:com.rogchen.common.xml.UtilDateTime.java
public static Timestamp getMonthEnd(Timestamp stamp) { return getMonthEnd(stamp, TimeZone.getDefault(), Locale.getDefault()); }
From source file:org.ngrinder.home.controller.HomeController.java
private void setLoginPageDate(ModelMap model) { TimeZone defaultTime = TimeZone.getDefault(); model.addAttribute("timezones", timeZones); model.addAttribute("defaultTime", defaultTime.getID()); }
From source file:com.hp.avmon.home.service.LicenseService.java
public static Timestamp getCurrentTime() { try {// w ww. java2 s. c o m Calendar cal = Calendar.getInstance(TimeZone.getDefault()); String DATE_FORMAT_HMS_d = "yyyy-MM-dd HH:mm:ss"; SimpleDateFormat formatwithHMSd = new SimpleDateFormat(DATE_FORMAT_HMS_d); formatwithHMSd.setTimeZone(TimeZone.getDefault()); Date currentdate_d = formatwithHMSd.parse(formatwithHMSd.format(cal.getTime())); long time = currentdate_d.getTime(); Timestamp currentTime = new Timestamp(time); return currentTime; } catch (Exception e) { // e.printStackTrace(); return null; } }
From source file:tw.com.sti.store.api.android.AndroidApiService.java
public List<NameValuePair> createRequestParams(String[] paramNames, String[] paramValues, boolean withToken, Integer appfilter, String userId, String pwd) { List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("store", storeId)); nvps.add(new BasicNameValuePair("aver", sdkVer)); nvps.add(new BasicNameValuePair("arel", sdkRel)); nvps.add(new BasicNameValuePair("cver", clientVer)); nvps.add(new BasicNameValuePair("lang", Locale.getDefault().toString())); TimeZone tz = TimeZone.getDefault(); nvps.add(new BasicNameValuePair("tzid", tz.getID())); nvps.add(new BasicNameValuePair("tzrawoffset", "" + tz.getRawOffset())); String time = "" + System.currentTimeMillis(); nvps.add(new BasicNameValuePair("time", time)); String vstring = storeId + "|" + time; if (userId != null && pwd != null) { vstring = storeId + "|" + time + "|" + userId + "|" + pwd; } else if (withToken && this.credential.getToken() != null && this.credential.getToken().length() > 0) { vstring = storeId + "|" + time + "|" + this.credential.getToken(); } else if (deviceId != null && subscriberId != null && simSerialNumber != null) { vstring = storeId + "|" + time + "|" + deviceId + "|" + subscriberId + "|" + simSerialNumber; }//from w ww . j av a2 s.c o m L.d("vstring=" + vstring); String vsign = ""; try { vsign = Dsa.sign(vstring, this.config.getApiPrivkey()); } catch (Exception e) { } nvps.add(new BasicNameValuePair("vsign", vsign)); nvps.add(new BasicNameValuePair("imei", deviceId)); nvps.add(new BasicNameValuePair("mac", macAddress)); nvps.add(new BasicNameValuePair("imsi", subscriberId)); nvps.add(new BasicNameValuePair("iccid", simSerialNumber)); nvps.add(new BasicNameValuePair("dvc", Build.MODEL)); nvps.add(new BasicNameValuePair("wpx", wpx)); nvps.add(new BasicNameValuePair("hpx", hpx)); if (appfilter == null) { //?appFilter() nvps.add(new BasicNameValuePair("appfilter", "" + appFilter)); } else { //?appfilter nvps.add(new BasicNameValuePair("appfilter", "" + appfilter)); } //??? if (this.config.getSnum() != null && this.config.getSnum().length() > 0) { nvps.add(new BasicNameValuePair("snum", this.config.getSnum())); } if (withToken && this.credential.getToken() != null && this.credential.getToken().length() > 0) { nvps.add(new BasicNameValuePair("token", this.credential.getToken())); } if (paramNames == null || paramValues == null) { return nvps; } if (paramNames.length != paramValues.length) { throw new IndexOutOfBoundsException("paramNames.length != paramValues.length"); } int count = paramNames.length; for (int i = 0; i < count; i++) { nvps.add(new BasicNameValuePair(paramNames[i], paramValues[i])); } return nvps; }
From source file:org.jfree.data.time.junit.MinuteTest.java
/** * Some checks for the getStart() method. *///from www .ja v a 2 s .c o m public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome")); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 0); cal.set(Calendar.MILLISECOND, 0); Minute m = new Minute(47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getStart()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:com.cloudera.sqoop.manager.OracleManagerTest.java
/** * Compare two lines. Normalize the dates we receive based on the expected * time zone./*from ww w . jav a2s .c o m*/ * @param expectedLine expected line * @param receivedLine received line * @throws IOException exception during lines comparison */ private void compareRecords(String expectedLine, String receivedLine) throws IOException { // handle null case if (expectedLine == null || receivedLine == null) { return; } // check if lines are equal if (expectedLine.equals(receivedLine)) { return; } // check if size is the same String[] expectedValues = expectedLine.split(","); String[] receivedValues = receivedLine.split(","); if (expectedValues.length != 7 || receivedValues.length != 7) { LOG.error("Number of expected fields did not match " + "number of received fields"); throw new IOException("Number of expected fields did not match " + "number of received fields"); } // check first 5 values boolean mismatch = false; for (int i = 0; !mismatch && i < 5; i++) { mismatch = !expectedValues[i].equals(receivedValues[i]); } if (mismatch) { throw new IOException("Expected:<" + expectedLine + "> but was:<" + receivedLine + ">"); } Date expectedDate = null; Date receivedDate = null; DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); int offset = TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 3600000; for (int i = 5; i < 7; i++) { // parse expected timestamp. try { expectedDate = df.parse(expectedValues[i]); } catch (ParseException ex) { LOG.error("Could not parse expected timestamp: " + expectedValues[i]); throw new IOException("Could not parse expected timestamp: " + expectedValues[i]); } // parse received timestamp try { receivedDate = df.parse(receivedValues[i]); } catch (ParseException ex) { LOG.error("Could not parse received timestamp: " + receivedValues[i]); throw new IOException("Could not parse received timestamp: " + receivedValues[i]); } // compare two timestamps considering timezone offset Calendar expectedCal = Calendar.getInstance(); expectedCal.setTime(expectedDate); expectedCal.add(Calendar.HOUR, offset); Calendar receivedCal = Calendar.getInstance(); receivedCal.setTime(receivedDate); if (!expectedCal.equals(receivedCal)) { throw new IOException("Expected:<" + expectedLine + "> but was:<" + receivedLine + ">, while timezone offset is: " + offset); } } }
From source file:net.antidot.sql.model.core.SQLConnector.java
/** * Return corresponding xsd timezone syntax from a given MySQL format. * References : MySQL format :/*from w w w . j a va 2 s. c om*/ * http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html XSD syntax * : http://www.schemacentral.com/sc/xsd/t-xsd_dateTime.html * * @param format * @return */ public static String getTimeZoneFromMySQLFormat(String format) { String result = null; if (format.equals("SYSTEM")) { // Use timezone system result = timeZoneToStr(TimeZone.getDefault()); } else if (format.indexOf(":") != -1) { // The value is given as a string indicating an offset from UTC // Complex problem : how determine time zome from its offset ? // But this MySQL format is already in xsd:date format if (format.equals("+00:00") || format.equals("-00:00")) result = "Z"; else result = format; } else { String[] IDs = TimeZone.getAvailableIDs(); for (String ID : IDs) { if (ID.equals(format)) { result = timeZoneToStr(TimeZone.getTimeZone(format)); break; } } } return result; }
From source file:com.jaspersoft.jasperserver.test.CoreDataCreateTestNG.java
private void addSchedulerResources() { final HolidayCalendar holidayCalendar = new HolidayCalendar(); Calendar calendar = new GregorianCalendar(2012, Calendar.JANUARY, 1); for (int year = 2012; year <= 2022; year++) { calendar.set(Calendar.YEAR, year); holidayCalendar.addExcludedDate(calendar.getTime()); }/* w w w .ja v a2 s . c om*/ holidayCalendar.setTimeZone(TimeZone.getDefault()); holidayCalendar.setDescription(HOLIDAY_CALENDAR_NAME); getReportScheduler().addCalendar(HOLIDAY_CALENDAR_NAME, holidayCalendar, true, true); }
From source file:com.pursuer.reader.easyrss.VerticalSingleItemView.java
@SuppressLint({ "NewApi", "SimpleDateFormat" }) public VerticalSingleItemView(final DataMgr dataMgr, final Context context, final String uid, final View menu, final VerticalItemViewCtrl itemViewCtrl) { this.dataMgr = dataMgr; this.context = context; this.item = dataMgr.getItemByUid(uid, ITEM_PROJECTION); this.fontSize = new SettingFontSize(dataMgr).getData(); this.theme = new SettingTheme(dataMgr).getData(); this.showTop = false; this.showBottom = false; this.menu = menu; this.itemViewCtrl = itemViewCtrl; this.imageClickTime = 0; final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.view = inflater.inflate(R.layout.single_item_view, null); // Disable hardware acceleration on Android 3.0-4.1 devices. if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); }// ww w.ja v a 2s . c o m lastItemView = view.findViewById(R.id.LastItemView); nextItemView = view.findViewById(R.id.NextItemView); itemScrollView = (OverScrollView) view.findViewById(R.id.ItemScrollView); itemScrollView.setTopScrollView(lastItemView); itemScrollView.setBottomScrollView(nextItemView); itemScrollView.setOnScrollChangeListener(this); itemScrollView.setOnTouchListener(this); final View btnShowOriginal = view.findViewById(R.id.BtnShowOriginal); btnShowOriginal.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(final View view, final MotionEvent event) { boolean ret = false; final TextView txt = (TextView) view.findViewById(R.id.BtnText); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: txt.setTextColor(0xFF787878); ret = true; break; case MotionEvent.ACTION_MOVE: ret = true; break; case MotionEvent.ACTION_CANCEL: txt.setTextColor(0xBB787878); ret = false; break; case MotionEvent.ACTION_UP: txt.setTextColor(0xBB787878); final SettingBrowserChoice setting = new SettingBrowserChoice(dataMgr); if (setting.getData() == SettingBrowserChoice.BROWSER_CHOICE_EXTERNAL) { final Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse(item.getHref())); context.startActivity(intent); } else if (VerticalSingleItemView.this.listener != null) { VerticalSingleItemView.this.listener.showWebsitePage(item.getUid(), false); } break; default: } return ret; } }); final View btnShowMobilized = view.findViewById(R.id.BtnShowMobilized); btnShowMobilized.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(final View view, final MotionEvent event) { boolean ret = false; final TextView txt = (TextView) view.findViewById(R.id.BtnText); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: txt.setTextColor(0xFF787878); ret = true; break; case MotionEvent.ACTION_MOVE: ret = true; break; case MotionEvent.ACTION_CANCEL: txt.setTextColor(0xBB787878); ret = false; break; case MotionEvent.ACTION_UP: txt.setTextColor(0xBB787878); if (VerticalSingleItemView.this.listener != null) { VerticalSingleItemView.this.listener.showWebsitePage(item.getUid(), true); } ret = true; break; default: } return ret; } }); { final ListItemItem lastItem = itemViewCtrl.getLastItem(item.getUid()); final TextView txt = (TextView) lastItemView.findViewById(R.id.LastItemTitle); txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize); if (lastItem == null) { lastUid = null; menu.findViewById(R.id.BtnPrevious).setEnabled(false); final ImageView img = (ImageView) lastItemView.findViewById(R.id.LastItemArrow); img.setImageResource(R.drawable.no_more_circle); txt.setText(R.string.TxtNoPreviousItem); } else { lastUid = lastItem.getId(); final View btnLast = menu.findViewById(R.id.BtnPrevious); btnLast.setEnabled(true); btnLast.setOnClickListener(new OnClickListener() { @Override public void onClick(final View view) { if (listener != null) { listener.showLastItem(); } } }); txt.setText(lastItem.getTitle()); } } { final ListItemItem nextItem = itemViewCtrl.getNextItem(item.getUid()); final TextView txt = (TextView) nextItemView.findViewById(R.id.NextItemTitle); txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize); if (nextItem == null) { nextUid = null; menu.findViewById(R.id.BtnNext).setEnabled(false); final ImageView img = (ImageView) nextItemView.findViewById(R.id.NextItemArrow); img.setImageResource(R.drawable.no_more_circle); txt.setText(R.string.TxtNoNextItem); } else { nextUid = nextItem.getId(); final View btnNext = menu.findViewById(R.id.BtnNext); btnNext.setEnabled(true); btnNext.setOnClickListener(new OnClickListener() { @Override public void onClick(final View view) { if (listener != null) { listener.showNextItem(); } } }); txt.setText(nextItem.getTitle()); } } final TextView title = (TextView) view.findViewById(R.id.ItemTitle); title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 3); title.setText(item.getTitle()); final TextView info = (TextView) view.findViewById(R.id.ItemInfo); info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 5); final StringBuilder infoText = new StringBuilder(); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); sdf.setTimeZone(TimeZone.getDefault()); infoText.append(sdf.format(Utils.timestampToDate(item.getTimestamp()))); if (item.getAuthor() != null && item.getAuthor().length() > 0) { infoText.append(" | By "); infoText.append(item.getAuthor()); } if (item.getSourceTitle() != null && item.getSourceTitle().length() > 0) { infoText.append(" ("); infoText.append(item.getSourceTitle()); infoText.append(")"); } info.setText(infoText); webView = (WebView) view.findViewById(R.id.webView); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.setBackgroundColor(context.getResources() .getColor(theme == SettingTheme.THEME_NORMAL ? R.color.NormalBackground : R.color.DarkBackground)); webView.setFocusable(false); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(final WebView view, final String url) { if (VerticalSingleItemView.this.imageClickTime > System.currentTimeMillis() - 1000) { return true; } final Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse(url)); context.startActivity(intent); return true; } }); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(final WebView view, final String url, final String message, final JsResult result) { if (VerticalSingleItemView.this.listener != null) { if (message.endsWith(".erss")) { VerticalSingleItemView.this.listener .onImageViewRequired(item.getStoragePath() + "/" + message); } else { VerticalSingleItemView.this.listener.onImageViewRequired(message); } } VerticalSingleItemView.this.imageClickTime = System.currentTimeMillis(); result.cancel(); return true; } }); updateButtonStar(); updateButtonSharing(); updateButtonOpenLink(); if (!item.getState().isRead()) { dataMgr.markItemAsReadWithTransactionByUid(uid); NetworkMgr.getInstance().startImmediateItemStateSyncing(); } }