Example usage for java.text SimpleDateFormat setTimeZone

List of usage examples for java.text SimpleDateFormat setTimeZone

Introduction

In this page you can find the example usage for java.text SimpleDateFormat setTimeZone.

Prototype

public void setTimeZone(TimeZone zone) 

Source Link

Document

Sets the time zone for the calendar of this DateFormat object.

Usage

From source file:air.com.snagfilms.utils.Utils.java

public static String getfilmriseParameters() {

    StringBuilder strBlr = null;//from   ww w . j  a va 2s  .c  om
    try {

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        long longs = System.currentTimeMillis();
        String timestamp = dateFormat.format(longs);
        ;
        String stringToSign = timestamp; // Query uses this string

        // Compute the signature and base64 encode it.
        String algorithm = "HmacSHA1";
        SecretKeySpec key = new SecretKeySpec(SECRET_KEY.getBytes(), algorithm);
        Mac mac = Mac.getInstance(algorithm);
        mac.init(key);

        String signature = new String(Base64.encodeBase64(mac.doFinal(stringToSign.getBytes())));
        System.out.println(signature);// required for Query
        signature = URLEncoder.encode(signature, "UTF-8");

        strBlr = new StringBuilder();
        strBlr.append(Constants.ACCESS_KEY);
        strBlr.append("=");
        strBlr.append(ACCESS_KEY);

        strBlr.append("&");
        strBlr.append(Constants.TIME_STAMP);
        strBlr.append("=");
        strBlr.append(timestamp);

        strBlr.append("&");
        strBlr.append(Constants.SIGNATURE);
        strBlr.append("=");
        strBlr.append(signature);

        strBlr.append("&");
        strBlr.append(Constants.SITE);
        strBlr.append("=");
        strBlr.append(Constants.filmrise);

        strBlr.append("&");
        strBlr.append(Constants.DEVICE);
        strBlr.append("=");
        strBlr.append("android");

        return strBlr.toString();

    } catch (Exception e) {

    }
    return null;
}

From source file:com.krawler.spring.authHandler.authHandler.java

public static DateFormat getDateFormatter(HttpServletRequest request) throws SessionExpiredException {
    String dateformat = "";
    String timeformat = authHandler.getUserTimeFormat(request);
    if (timeformat.equals("1")) {
        dateformat = "MMMM d, yyyy hh:mm:ss aa";
    } else/*w w  w.j av  a 2  s  . co  m*/
        dateformat = "MMMM d, yyyy HH:mm:ss";
    SimpleDateFormat sdf = new SimpleDateFormat(dateformat);
    sdf.setTimeZone(TimeZone.getTimeZone("GMT" + getTimeZoneDifference(request)));
    return sdf;
}

From source file:facebook4j.internal.util.z_F4JInternalParseUtil.java

private static Date parseISO8601Date(String dateString, TimeZone timezone) {
    try {/* www  .jav a 2s  .  c o m*/
        return new SimpleDateFormat(ISO8601_DATE_FORMAT).parse(dateString);
    } catch (ParseException e1) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(ISO8601_DATE_FORMAT_WITHOUT_TZ);
            sdf.setTimeZone(timezone);
            return sdf.parse(dateString);
        } catch (ParseException e2) {
            try {
                SimpleDateFormat sdf = new SimpleDateFormat(ISO8601_DATE_FORMAT_WITHOUT_TIME);
                sdf.setTimeZone(timezone);
                return sdf.parse(dateString);
            } catch (ParseException e3) {
                return null;
            }
        }
    }
}

From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.framework.Util.java

public static String dateToString(Date date, String dateFormatStr) {
    if (date == null) {
        return "NULL";
    }/*ww  w.j  av a  2s .  co  m*/
    SimpleDateFormat dateFormat = new SimpleDateFormat(dateFormatStr, Locale.getDefault());
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    String formatted = dateFormat.format(date);

    return formatted;
}

From source file:com.hurence.logisland.utils.DateUtils.java

public static Date getDateFromLogString(String dateString) {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy:hh:mm:ss", new Locale("en", "US"));
    sdf.setTimeZone(tz);

    Date result = null;/*from w  ww.j av  a 2 s .co  m*/
    try {
        result = sdf.parse(dateString);
    } catch (ParseException e) {
        log.warn(e.getMessage());
    }
    return result;

}

From source file:com.akamai.edgegrid.signer.EdgeGridV1Signer.java

private static String formatTimeStamp(long time) {
    SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ssZ");
    Date date = new Date(time);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    return format.format(date);
}

From source file:edu.cmu.android.restaurant.authentication.NetworkUtilities.java

/**
 * Fetches the list of friend data updates from the server
 * /*from ww  w .ja va 2 s.co  m*/
 * @param account
 *            The account being synced.
 * @param authtoken
 *            The authtoken stored in AccountManager for this account
 * @param lastUpdated
 *            The last time that sync was performed
 * @return list The list of updates received from the server.
 */
public static List<User> fetchFriendUpdates(Account account, String authtoken, Date lastUpdated)
        throws JSONException, ParseException, IOException, AuthenticationException {
    final ArrayList<User> friendList = new ArrayList<User>();
    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(PARAM_USERNAME, account.name));
    params.add(new BasicNameValuePair(PARAM_PASSWORD, authtoken));
    if (lastUpdated != null) {
        final SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
        params.add(new BasicNameValuePair(PARAM_UPDATED, formatter.format(lastUpdated)));
    }
    Log.i(TAG, params.toString());

    HttpEntity entity = null;
    entity = new UrlEncodedFormEntity(params);
    final HttpPost post = new HttpPost(FETCH_FRIEND_UPDATES_URI);
    post.addHeader(entity.getContentType());
    post.setEntity(entity);
    maybeCreateHttpClient();

    final HttpResponse resp = mHttpClient.execute(post);
    final String response = EntityUtils.toString(resp.getEntity());

    if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        // Succesfully connected to the samplesyncadapter server and
        // authenticated.
        // Extract friends data in json format.
        final JSONArray friends = new JSONArray(response);
        Log.d(TAG, response);
        for (int i = 0; i < friends.length(); i++) {
            friendList.add(User.valueOf(friends.getJSONObject(i)));
        }
    } else {
        if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            Log.e(TAG, "Authentication exception in fetching remote contacts");
            throw new AuthenticationException();
        } else {
            Log.e(TAG, "Server error in fetching remote contacts: " + resp.getStatusLine());
            throw new IOException();
        }
    }
    return friendList;
}

From source file:com.anjz.util.CookieUtils.java

private static void getCookieHeaderValue(final Cookie cookie, final StringBuffer buf, final boolean httpOnly) {
    final int version = cookie.getVersion();

    // this part is the same for all cookies

    String name = cookie.getName(); // Avoid NPE on malformed cookies
    if (name == null) {
        name = "";
    }//from   w  ww .  j ava2s.co m
    String value = cookie.getValue();
    if (value == null) {
        value = "";
    }

    buf.append(name);
    buf.append("=");

    maybeQuote(version, buf, value);

    // add version 1 specific information
    if (version == 1) {
        // Version=1 ... required
        buf.append("; Version=1");

        // Comment=comment
        if (cookie.getComment() != null) {
            buf.append("; Comment=");
            maybeQuote(version, buf, cookie.getComment());
        }
    }

    // add domain information, if present

    if (cookie.getDomain() != null) {
        buf.append("; Domain=");
        maybeQuote(version, buf, cookie.getDomain());
    }

    // Max-Age=secs/Discard ... or use old "Expires" format
    if (cookie.getMaxAge() >= 0) {
        if (version == 0) {
            buf.append("; Expires=");
            SimpleDateFormat dateFormat = new SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US);
            dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); //GMT?
            if (cookie.getMaxAge() == 0) {
                dateFormat.format(new Date(10000), buf, new FieldPosition(0));
            } else {
                dateFormat.format(new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000L), buf,
                        new FieldPosition(0));
            }
        } else {
            buf.append("; Max-Age=");
            buf.append(cookie.getMaxAge());
        }
    } else if (version == 1) {
        buf.append("; Discard");
    }

    // Path=path
    if (cookie.getPath() != null) {
        buf.append("; Path=");
        maybeQuote(version, buf, cookie.getPath());
    }

    // Secure
    if (cookie.getSecure()) {
        buf.append("; Secure");
    }

    // HttpOnly
    if (httpOnly) {
        buf.append("; HttpOnly");
    }
}

From source file:gov.nih.nci.cabig.caaers.utils.DateUtils.java

public static String formatDate(Date d, String pattern, TimeZone tz) {
    //BJ: date formats are not thread safe.
    SimpleDateFormat df = new SimpleDateFormat(pattern);
    df.setTimeZone(tz);
    return df.format(d);
}

From source file:com.netprogs.minecraft.plugins.social.command.util.MessageUtil.java

public static List<MessageParameter> createCoolDownFormatting(long timeRemaining) {

    SimpleDateFormat hourFormat = new SimpleDateFormat("HH");
    hourFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    SimpleDateFormat minFormat = new SimpleDateFormat("mm");
    minFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    SimpleDateFormat secFormat = new SimpleDateFormat("ss");
    secFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    MessageParameter hour = new MessageParameter("<hours>", hourFormat.format(timeRemaining), ChatColor.GOLD);
    MessageParameter min = new MessageParameter("<minutes>", minFormat.format(timeRemaining), ChatColor.GOLD);
    MessageParameter sec = new MessageParameter("<seconds>", secFormat.format(timeRemaining), ChatColor.GOLD);

    List<MessageParameter> params = new ArrayList<MessageParameter>();
    params.add(hour);//w  w  w .  jav  a  2 s.c o m
    params.add(min);
    params.add(sec);

    return params;
}