Example usage for java.util SimpleTimeZone SimpleTimeZone

List of usage examples for java.util SimpleTimeZone SimpleTimeZone

Introduction

In this page you can find the example usage for java.util SimpleTimeZone SimpleTimeZone.

Prototype

public SimpleTimeZone(int rawOffset, String ID) 

Source Link

Document

Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID with no daylight saving time schedule.

Usage

From source file:com.hzq.car.CarTest.java

/**
 * ?/*from ww  w. j a v  a2 s .com*/
 */
private String formatIso8601Date(Date date) {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    df.setTimeZone(new SimpleTimeZone(0, "GMT"));
    return df.format(date);
}

From source file:com.parse.ParseObjectCurrentCoderTest.java

@Test
public void testObjectSerializationFormat() throws Exception {
    ParseObject childObject = new ParseObject("child");
    childObject.setObjectId("childObjectId");

    DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
    format.setTimeZone(new SimpleTimeZone(0, "GMT"));

    String dateString = "2011-08-12T01:06:05Z";
    Date date = format.parse(dateString);

    String jsonString = "{" + "'id':'wnAiJVI3ra'," + "'updated_at':'" + dateString + "',"
            + "'pointers':{'child':['child','" + childObject.getObjectId() + "']}," + "'classname':'myClass',"
            + "'dirty':true," + "'data':{'foo':'bar'}," + "'created_at':'2011-08-12T01:06:05Z',"
            + "'deletedKeys':['toDelete']" + "}";

    ParseObjectCurrentCoder coder = ParseObjectCurrentCoder.get();
    JSONObject json = new JSONObject(jsonString);
    ParseObject.State state = coder.decode(new ParseObject.State.Builder("Test"), json, ParseDecoder.get())
            .build();//from w ww  .ja v a2 s  .  c  o  m

    assertEquals("wnAiJVI3ra", state.objectId());
    assertEquals("bar", state.get("foo"));
    assertEquals(date.getTime(), state.createdAt());
    assertEquals(((ParseObject) state.get("child")).getObjectId(), childObject.getObjectId());

    // Test that objects can be serialized and deserialized without timestamps
    String jsonStringWithoutTimestamps = "{" + "'id':'wnAiJVI3ra'," + "'pointers':{'child':['child','"
            + childObject.getObjectId() + "']}," + "'classname':'myClass'," + "'dirty':true,"
            + "'data':{'foo':'bar'}," + "'deletedKeys':['toDelete']" + "}";

    json = new JSONObject(jsonStringWithoutTimestamps);
    state = coder.decode(new ParseObject.State.Builder("Test"), json, ParseDecoder.get()).build();
    assertEquals("wnAiJVI3ra", state.objectId());
}

From source file:org.commoncrawl.service.crawler.HttpFetcher.java

public HttpFetcher(int maxOpenSockets, InetSocketAddress[] crawlInterfaceList, String crawlerName) {
    _maxSockets = maxOpenSockets;//from   ww  w .j a  v  a 2s . c om
    _active = new NIOHttpConnection[_maxSockets];
    _activeVersions = new short[_maxSockets];
    _trailingVersions = new short[_maxSockets];

    _selector = CrawlerServer.getServer().getEventLoop().getSelector();
    _resolver = CrawlerServer.getServer().getDNSServiceResolver();

    _urlsPerSecMovingAverage = new MovingAverage(200);
    _kbPerSecMovingAverage = new MovingAverage(200);
    _avgDownloadSize = new MovingAverage(200);
    _urlsPerSecSmoothed = new SmoothedAverage(.25);
    _kbPerSecSmoothed = new SmoothedAverage(.25);

    _crawlInterfaces = crawlInterfaceList;
    _crawlerName = crawlerName;
    http_date_format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
    http_date_format.setTimeZone(new SimpleTimeZone(0, "GMT"));

    // set the default ccbot user agent string 
    NIOHttpConnection.setDefaultUserAgentString("CCBot/1.0 (+http://www.commoncrawl.org/bot.html)");
}

From source file:org.ambraproject.views.AnnotationView.java

/**
 * Create a new AnnotationView//from   w  ww  . jav a 2  s. c  o  m
 *
 * @param annotation    the annotation being wrapped
 * @param articleTitle  the title of the article that is annotated
 * @param articleDoi    the doi of the article that is annotated
 * @param fullReplyTree a full map of all child replies, from Id -> all replies to the annotation with that id.
 *                      Allowed to be null or empty
 */
public AnnotationView(Annotation annotation, String articleDoi, String articleTitle,
        @Nullable Map<Long, List<Annotation>> fullReplyTree) {
    this.ID = annotation.getID();
    this.articleDoi = articleDoi;
    this.articleTitle = articleTitle;
    if (annotation.getAnnotationUri() != null) {
        this.annotationUri = annotation.getAnnotationUri().replaceFirst("info:doi/", "");
    } else {
        this.annotationUri = null;
    }
    this.originalTitle = annotation.getTitle();
    String escapedTitle = TextUtils.escapeHtml(annotation.getTitle());
    this.title = escapedTitle;

    if (annotation.getBody() == null) {
        this.originalBody = "";
        this.body = "";
        this.truncatedBody = "";
        this.bodyWithUrlLinkingNoPTags = "";
        this.truncatedBodyWithUrlLinkingNoPTags = "";
        this.bodyWithHighlightedText = "";
    } else {
        this.originalBody = annotation.getBody();
        this.body = TextUtils.hyperlinkEnclosedWithPTags(TextUtils.escapeHtml(annotation.getBody()), 25);
        this.truncatedBody = TextUtils.hyperlinkEnclosedWithPTags(
                TextUtils.truncateText(TextUtils.escapeHtml(annotation.getBody()), TRUNCATED_COMMENT_LENGTH),
                25);
        this.bodyWithUrlLinkingNoPTags = TextUtils.hyperlink(TextUtils.escapeHtml(annotation.getBody()), 25);
        this.truncatedBodyWithUrlLinkingNoPTags = TextUtils.hyperlink(
                TextUtils.truncateText(TextUtils.escapeHtml(annotation.getBody()), TRUNCATED_COMMENT_LENGTH),
                25);
        if (annotation.getHighlightedText() != null) {
            // highlighted text contains the highlighted text
            // and a link to the paragraph location of where the highlighted text is located
            String bodyWithHt = annotation.getHighlightedText() + "\n\n" + annotation.getBody();
            this.bodyWithHighlightedText = TextUtils
                    .hyperlinkEnclosedWithPTags(TextUtils.escapeHtml(bodyWithHt), 150);
        } else {
            this.bodyWithHighlightedText = this.body;
        }
    }

    if (annotation.getCompetingInterestBody() == null) {
        this.competingInterestStatement = "";
        this.truncatedCompetingInterestStatement = "";
    } else {
        this.competingInterestStatement = TextUtils.escapeHtml(annotation.getCompetingInterestBody());
        this.truncatedCompetingInterestStatement = TextUtils.truncateText(
                TextUtils.escapeHtml(annotation.getCompetingInterestBody()), TRUNCATED_COMMENT_LENGTH);
    }

    this.creatorID = annotation.getCreator().getID();
    this.creatorDisplayName = annotation.getCreator().getDisplayName();
    this.creatorFormattedName = createFormattedName(annotation.getCreator());
    this.articleID = annotation.getArticleID();
    this.parentID = annotation.getParentID();
    this.type = annotation.getType();

    //Defensive copy
    Calendar date = Calendar.getInstance();
    date.setTime(annotation.getCreated());
    this.created = date.getTime();

    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    fmt.setTimeZone(new SimpleTimeZone(0, "UTC"));
    this.createdFormatted = fmt.format(created);

    if (fullReplyTree == null || fullReplyTree.isEmpty()) {
        this.replies = EMPTY_ARRAY;
        this.lastReplyDate = this.created;
        this.totalNumReplies = 0;
    } else {
        List<Annotation> repliesToThis = fullReplyTree.get(annotation.getID());
        if (repliesToThis == null || repliesToThis.isEmpty()) {
            this.replies = EMPTY_ARRAY;
        } else {
            //sort the replies by date so our reply list will be ordered, earliest first
            Collections.sort(repliesToThis, REPLY_COMPARATOR);
            this.replies = new AnnotationView[repliesToThis.size()];
            for (int i = 0; i < repliesToThis.size(); i++) {
                this.replies[i] = new AnnotationView(repliesToThis.get(i), articleDoi, articleTitle,
                        fullReplyTree);
            }
        }
        //now populate lastReplyDate and totalNumReplies
        this.totalNumReplies = calculateTotalNumReplies();
        this.lastReplyDate = calculateMostRecentReplyDate();
    }
}

From source file:com.ibm.jaql.json.type.JsonDate.java

/** Converts the given format string into a {@link DateFormat}. */
public static DateFormat getFormat(String formatString) {
    SimpleDateFormat format = new SimpleDateFormat(formatString); // TODO: add cache of formats
    if (formatString.endsWith("'Z'") || formatString.endsWith("'z'")) {
        TimeZone tz = new SimpleTimeZone(0, "UTC");
        format.setTimeZone(tz);/*from  w ww.  j a v a 2s  .  co m*/
    }
    return format;
}

From source file:com.qut.middleware.esoe.sso.impl.AuthenticationAuthorityProcessorFuncTest.java

/**
 * Creates a valid SAML AuthnRequest like would be supplied by an SPEP
 * //from  www .j av a 2 s.c  om
 * @param allowCreation
 *            field to modify in the request to cause a difference in generated output.
 * @param tzOffset
 *            Specify an offset when creating xml timestamps. Specification says this must be set to 0. Any
 *            variations should cause SAML validation to reject the document.
 * @return String containing SAML AuthnRequest
 */
private byte[] generateValidRequest(boolean allowCreation, int tzOffset) throws Exception {
    AudienceRestriction audienceRestriction = new AudienceRestriction();
    Conditions conditions = new Conditions();
    NameIDType nameID = new NameIDType();
    NameIDType issuer = new NameIDType();
    NameIDPolicy policy = new NameIDPolicy();
    Subject subject = new Subject();
    Signature signature = new Signature();
    AuthnRequest authnRequest = new AuthnRequest();
    byte[] result;

    /* GMT timezone */
    SimpleTimeZone gmt = new SimpleTimeZone(tzOffset, ConfigurationConstants.timeZone);

    /* GregorianCalendar with the GMT time zone */
    GregorianCalendar calendar = new GregorianCalendar(gmt);
    XMLGregorianCalendar xmlCalendar = new XMLGregorianCalendarImpl(calendar);

    audienceRestriction.getAudiences().add("spep-n1.qut.edu.au");
    audienceRestriction.getAudiences().add("spep-n2.qut.edu.au");
    conditions.getConditionsAndOneTimeUsesAndAudienceRestrictions().add(audienceRestriction);

    nameID.setValue("beddoes@qut.com");
    nameID.setFormat("urn:oasis:names:tc:SAML:2.0:something");

    subject.setNameID(nameID);
    issuer.setValue(this.issuer);

    policy.setAllowCreate(allowCreation);
    authnRequest.setNameIDPolicy(policy);

    authnRequest.setSignature(signature);
    authnRequest.setSubject(subject);
    authnRequest.setConditions(conditions);

    authnRequest.setForceAuthn(false);
    authnRequest.setIsPassive(false);
    authnRequest.setAssertionConsumerServiceIndex(0);
    authnRequest.setProviderName("spep-n1");
    authnRequest.setID(this.issuer);
    authnRequest.setVersion("2.0");
    authnRequest.setIssueInstant(xmlCalendar);
    authnRequest.setIssuer(issuer);

    result = marshaller.marshallSigned(authnRequest);

    SAMLValidator validator = new SAMLValidatorImpl(new IdentifierCacheImpl(), 100);

    validator.getRequestValidator().validate(authnRequest);

    return Base64.encodeBase64(result);
}

From source file:org.dasein.cloud.aws.storage.S3Method.java

private String getDate() throws CloudException {
    if (provider.getEC2Provider().isStorage() && "google".equalsIgnoreCase(provider.getProviderName())) {
        SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ssz", new Locale("US"));
        Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));

        format.setCalendar(cal);//from w w w  .j  a va2  s . c o  m
        return format.format(new Date());
    } else {
        SimpleDateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
        Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));

        fmt.setCalendar(cal);
        return fmt.format(new Date());
    }
}

From source file:ti.mobileapptracker.MobileapptrackerModule.java

@Kroll.method
public void setEventDate1(String dateString) {

    SimpleDateFormat sdf = new SimpleDateFormat(MAT_DATE_TIME_FORMAT, Locale.ENGLISH);
    sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));

    Date date;/*from  ww  w.  j  a  va 2 s. c o  m*/

    try {
        date = sdf.parse(dateString);

        mat.setEventDate1(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:org.springframework.integration.sqs.AWSSecurityHandler.java

/**
 * Calculates a time stamp from "now" in UTC and returns it in ISO8601
 * string format. According to/*from   ww w  . j a  va2  s  .  c om*/
 * http://docs.amazonwebservices.com/AWSSimpleQueueService
 * /2008-01-01/SQSDeveloperGuide/NotUsingWSSecurity.html the soap message
 * expires 15 minutes after this time stamp. AWS only supports UTC and it's
 * canonical representation as 'Z' in an ISO8601 time string. See
 * http://www.w3.org/TR/xmlschema-2/#dateTime for more details.
 * @return ISO8601 time stamp string for "now" in UTC.
 */
private String getTimestamp() {
    // <aws:Timestamp>2008-02-10T23:59:59Z</aws:Timestamp>
    Calendar aGregorian = Calendar.getInstance();
    SimpleTimeZone aUTC = new SimpleTimeZone(0, "UTC");
    SimpleDateFormat aISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

    aISO8601.setTimeZone(aUTC);
    return aISO8601.format(aGregorian.getTime());
}

From source file:ti.mobileapptracker.MobileapptrackerModule.java

@Kroll.method
public void setEventDate2(String dateString) {

    SimpleDateFormat sdf = new SimpleDateFormat(MAT_DATE_TIME_FORMAT, Locale.ENGLISH);
    sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));

    Date date;//from   w  ww  .  ja v  a 2 s .co  m

    try {
        date = sdf.parse(dateString);

        mat.setEventDate2(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
}