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:it.jugpadova.blol.FeedsBoTest.java

public void testConvertDateAndTimeBrazil() throws ParseException {
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    df.setTimeZone(TimeZone.getTimeZone("America/Sao_Paulo"));
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    net.fortuna.ical4j.model.TimeZone tz = registry.getTimeZone("America/Sao_Paulo");
    Date d = df.parse("18/09/2009");
    net.fortuna.ical4j.model.Date cd1 = feedsBo.convertDateAndTime(d, "12:00 AM", tz);
    assertEquals("20090918T120000", cd1.toString());
    net.fortuna.ical4j.model.Date cd2 = feedsBo.convertDateAndTime(d, "05:00 PM", tz);
    assertEquals("20090918T170000", cd2.toString());
}

From source file:com.mercandalli.android.apps.files.user.UserConversationMessageModel.java

public String getAdapterSubtitle() {
    String date = date_creation.toString();
    SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
    dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC"));
    SimpleDateFormat dateFormatLocal = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
    try {//from w  w  w  .j  a va  2  s.  c om
        date = TimeUtils.printDifferencePast(date_creation,
                dateFormatLocal.parse(dateFormatGmt.format(new Date())));
    } catch (ParseException e) {
        Log.e(getClass().getName(), "Exception", e);
    }
    return getUsername() + "  " + date + " ago";
}

From source file:com.xerox.amazonws.ec2.UploadPolicy.java

public String getPolicyString() {
    StringBuilder json = new StringBuilder("{\n");
    json.append("\"expiration\": \"");
    final String DateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'";
    SimpleDateFormat format = new SimpleDateFormat(DateFormat, Locale.US);
    format.setTimeZone(TimeZone.getTimeZone("GMT"));
    json.append(format.format(new Date(System.currentTimeMillis() + (minutesToExpiration * 60000L))));
    json.append("\",\n");
    json.append("\"conditions\": [\n");

    json.append("{\"acl\": \"");
    json.append(acl);//from   w ww .  j  ava 2  s.co  m
    json.append("\"},\n");

    json.append("{\"bucket\": \"");
    json.append(bucket);
    json.append("\"},\n");

    json.append("[\"starts-with\", \"$key\", \"");
    json.append(prefix);
    json.append("\"],\n");

    json.append("]\n}");
    logger.debug("JSON policy string = " + json.toString());
    return new String(Base64.encodeBase64(json.toString().getBytes()));
}

From source file:com.funambol.exchange.util.DateTools.java

/**
 * Make a date from a client date to webdav date
 * //from   w  ww  .java 2s  .  c  o  m
 * @param date
 *            client date
 * @return a Date
 * @throws XmlParseException
 */
public static Date clientDateToDate(String date) throws XmlParseException {

    SimpleDateFormat formatter;
    Date timestamp;

    String format;

    try {

        if (date != null) {

            if (date.indexOf("Z") != -1) {
                format = DATETIME_FORMAT_CLIENT_UTC;
            } else {
                //
                // for nokia phone utc bug
                //
                format = DATETIME_FORMAT_CLIENT_NO_UTC;
            }

            formatter = new SimpleDateFormat(format);
            formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
            timestamp = formatter.parse(date);

            return timestamp;

        } else {
            return null;
        }
    } catch (ParseException e) {
        throw new XmlParseException(e.toString());
    }
}

From source file:jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationPlugin.java

private String createTimestamp() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'_'HHmmss");
    sdf.setTimeZone(TimeZone.getDefault());
    String timestamp = sdf.format(new Date());
    return timestamp;
}

From source file:net.paslavsky.springrest.HttpHeadersHelperTest.java

private DateFormat createDateFormat() {
    SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    return dateFormat;
}

From source file:com.amazonaws.services.ec2.util.S3UploadPolicy.java

/**
 * Creates a new S3 upload policy object from the specified parameters. Once
 * constructed, callers can access the policy string and policy signature to
 * use with the EC2 bundling API./*  w w w .  j a  v a 2 s  .c o m*/
 *
 * @param awsAccessKeyId
 *            The AWS access key ID for the S3 bucket the bundling artifacts
 *            should be stored in.
 * @param awsSecretKey
 *            The AWS secret key for the specified access key.
 * @param bucketName
 *            The name of the bucket to store the bundling artifacts in.
 * @param prefix
 *            The prefix for the bundling artifacts.
 * @param expireInMinutes
 *            The number of minutes before the upload policy expires and is
 *            unable to be used.
 */
public S3UploadPolicy(String awsAccessKeyId, String awsSecretKey, String bucketName, String prefix,
        int expireInMinutes) {
    Calendar expirationDate = Calendar.getInstance();
    expirationDate.add(Calendar.MINUTE, expireInMinutes);
    SimpleDateFormat ISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    ISO8601.setTimeZone(new SimpleTimeZone(0, "GMT"));
    StringBuilder builder = new StringBuilder();
    builder.append("{").append("\"expiration\": \"").append(ISO8601.format(expirationDate.getTime()))
            .append("\",").append("\"conditions\": [").append("{\"bucket\": \"").append(bucketName)
            .append("\"},").append("{\"acl\": \"").append("ec2-bundle-read").append("\"},")
            .append("[\"starts-with\", \"$key\", \"").append(prefix).append("\"]").append("]}");
    try {
        this.policyString = base64Encode(builder.toString().getBytes("UTF-8"));
        this.policySignature = signPolicy(awsSecretKey, policyString);
    } catch (Exception ex) {
        throw new RuntimeException("Unable to generate S3 upload policy", ex);
    }
}

From source file:lydichris.smashbracket.controllers.TournamentController.java

@RequestMapping(value = "/tournaments", method = RequestMethod.POST)
Tournament createTournament(@RequestParam String name, @RequestParam String description,
        @RequestParam(value = "maxEntrants", required = false, defaultValue = "0") int maxEntrants,
        @RequestParam String game, @RequestParam TournamentType tournamentType, @RequestParam String startTime,
        @RequestParam String hostId) throws ParseException {
    SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:m:s zzz", Locale.US);
    formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
    Date startTimeDate = formatter.parse(startTime);
    //Should take in userName for host somehow
    //Consider adding location
    return tournamentService.createTournament(name, description, maxEntrants, game, tournamentType,
            startTimeDate, hostId);//from w  w w.j a va 2  s .  c om
}

From source file:lydichris.smashbracket.controllers.TournamentController.java

@RequestMapping(value = "/tournaments", method = RequestMethod.PUT)
Tournament editTournament(@RequestParam String uuid, @RequestParam String name,
        @RequestParam String description,
        @RequestParam(value = "maxEntrants", required = false) int maxEntrants, @RequestParam String game,
        @RequestParam TournamentType tournamentType, @RequestParam String startTime,
        @RequestParam String hostId, @RequestParam boolean seed) throws ParseException {

    SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:m:s zzz", Locale.US);
    formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
    Date startTimeDate = formatter.parse(startTime);

    return tournamentService.editTournament(uuid, name, description, maxEntrants, game, tournamentType,
            startTimeDate, hostId, seed);
}

From source file:com.oembedler.moon.graphql.engine.type.GraphQLDateType.java

public GraphQLDateType(String name, String description, String dateFormat) {
    super(name, description, new Coercing() {
        private final TimeZone timeZone = TimeZone.getTimeZone("UTC");

        @Override/*from  w ww  .  j  av a 2s.  c  o m*/
        public Object serialize(Object input) {
            if (input instanceof String) {
                return parse((String) input);
            } else if (input instanceof Date) {
                return format((Date) input);
            } else if (input instanceof Long) {
                return new Date((Long) input);
            } else if (input instanceof Integer) {
                return new Date(((Integer) input).longValue());
            } else {
                throw new GraphQLException("Wrong timestamp value");
            }
        }

        @Override
        public Object parseValue(Object input) {
            return serialize(input);
        }

        @Override
        public Object parseLiteral(Object input) {
            if (!(input instanceof StringValue))
                return null;
            return parse(((StringValue) input).getValue());
        }

        private String format(Date input) {
            return getSimpleDateFormat().format(input.getTime());
        }

        private Date parse(String input) {
            Date date = null;
            try {
                date = getSimpleDateFormat().parse(input);
            } catch (Exception e) {
                throw new GraphQLException("Can not parse input date", e);
            }
            return date;
        }

        private SimpleDateFormat getSimpleDateFormat() {
            SimpleDateFormat df = new SimpleDateFormat(dateFormat);
            df.setTimeZone(timeZone);
            return df;
        }
    });
    Assert.notNull(dateFormat, "Date format must not be null");
}