List of usage examples for java.util TimeZone getOffset
public abstract int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds);
From source file:Main.java
public static void main(String args[]) { TimeZone timezone = TimeZone.getTimeZone("Europe/Paris"); // checking offset value System.out.println("Offset value is :" + timezone.getOffset(1, 2011, 2, 2, 2, 300)); }
From source file:VASSAL.chat.HttpMessageServer.java
public Message[] getMessages() { final ArrayList<Message> msgList = new ArrayList<Message>(); try {/*from w w w. j a va 2 s. c o m*/ for (String msg : getMessagesURL.doGet(prepareInfo())) { try { StringTokenizer st = new StringTokenizer(msg, "&"); //$NON-NLS-1$ String s = st.nextToken(); String sender = s.substring(s.indexOf('=') + 1); //$NON-NLS-1$ String date = st.nextToken(); date = date.substring(date.indexOf('=') + 1); //$NON-NLS-1$ s = st.nextToken(""); //$NON-NLS-1$ String content = StringUtils .join(new SequenceEncoder.Decoder(s.substring(s.indexOf('=') + 1), '|'), '\n'); content = restorePercent(content); Date created = null; try { long time = Long.parseLong(date); TimeZone t = TimeZone.getDefault(); time += t.getOffset(Calendar.ERA, Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_YEAR, Calendar.DAY_OF_WEEK, Calendar.MILLISECOND); created = new Date(time); } catch (NumberFormatException e1) { created = new Date(); } msgList.add(new Message(sender, content, created)); } catch (NoSuchElementException ex) { System.err.println("Badly formatted message in HttpMessageServer: " + msg); //$NON-NLS-1$ } } } catch (IOException ex) { System.err.println("IOException retrieving messages from " + getMessagesURL); //$NON-NLS-1$ } return msgList.toArray(new Message[msgList.size()]); }
From source file:com.liferay.ide.server.remote.AbstractRemoteServerPublisher.java
protected void addToZip(IPath path, IResource resource, ZipOutputStream zip, boolean adjustGMTOffset) throws IOException, CoreException { switch (resource.getType()) { case IResource.FILE: ZipEntry zipEntry = new ZipEntry(path.toString()); zip.putNextEntry(zipEntry);//www . ja v a 2s . com InputStream contents = ((IFile) resource).getContents(); if (adjustGMTOffset) { TimeZone currentTimeZone = TimeZone.getDefault(); Calendar currentDt = new GregorianCalendar(currentTimeZone, Locale.getDefault()); // Get the Offset from GMT taking current TZ into account int gmtOffset = currentTimeZone.getOffset(currentDt.get(Calendar.ERA), currentDt.get(Calendar.YEAR), currentDt.get(Calendar.MONTH), currentDt.get(Calendar.DAY_OF_MONTH), currentDt.get(Calendar.DAY_OF_WEEK), currentDt.get(Calendar.MILLISECOND)); zipEntry.setTime(System.currentTimeMillis() + (gmtOffset * -1)); } try { IOUtils.copy(contents, zip); } finally { contents.close(); } break; case IResource.FOLDER: case IResource.PROJECT: IContainer container = (IContainer) resource; IResource[] members = container.members(); for (IResource res : members) { addToZip(path.append(res.getName()), res, zip, adjustGMTOffset); } } }