Search in sources :

Example 81 with SimpleDateFormat

use of java.text.SimpleDateFormat in project elastic-job by dangdangdotcom.

the class StatisticManager method getOnlineDate.

private Date getOnlineDate() {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    Date onlineDate = null;
    try {
        onlineDate = formatter.parse("2016-12-16");
    } catch (final ParseException ex) {
    }
    return onlineDate;
}
Also used : ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 82 with SimpleDateFormat

use of java.text.SimpleDateFormat in project che by eclipse.

the class GitHubKeyUploader method uploadKey.

@Override
public void uploadKey(String publicKey) throws IOException, UnauthorizedException {
    final OAuthToken token = tokenProvider.getToken("github", EnvironmentContext.getCurrent().getSubject().getUserId());
    if (token == null || token.getToken() == null) {
        LOG.debug("Token not found, user need to authorize to upload key.");
        throw new UnauthorizedException("To upload SSH key you need to authorize.");
    }
    StringBuilder answer = new StringBuilder();
    final String url = String.format("https://api.github.com/user/keys?access_token=%s", token.getToken());
    final List<GitHubKey> gitHubUserPublicKeys = getUserPublicKeys(url, answer);
    for (GitHubKey gitHubUserPublicKey : gitHubUserPublicKeys) {
        if (publicKey.startsWith(gitHubUserPublicKey.getKey())) {
            return;
        }
    }
    final Map<String, String> postParams = new HashMap<>(2);
    postParams.put("title", "IDE SSH Key (" + new SimpleDateFormat().format(new Date()) + ")");
    postParams.put("key", new String(publicKey.getBytes()));
    final String postBody = JsonHelper.toJson(postParams);
    LOG.debug("Upload public key: {}", postBody);
    int responseCode;
    HttpURLConnection conn = null;
    try {
        conn = (HttpURLConnection) new URL(url).openConnection();
        conn.setInstanceFollowRedirects(false);
        conn.setRequestMethod(HttpMethod.POST);
        conn.setRequestProperty(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
        conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
        conn.setRequestProperty(HttpHeaders.CONTENT_LENGTH, String.valueOf(postBody.length()));
        conn.setDoOutput(true);
        try (OutputStream out = conn.getOutputStream()) {
            out.write(postBody.getBytes());
        }
        responseCode = conn.getResponseCode();
    } finally {
        if (conn != null) {
            conn.disconnect();
        }
    }
    LOG.debug("Upload key response code: {}", responseCode);
    if (responseCode != HttpURLConnection.HTTP_CREATED) {
        throw new IOException(String.format("%d: Failed to upload public key to https://github.com/", responseCode));
    }
}
Also used : HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) IOException(java.io.IOException) Date(java.util.Date) URL(java.net.URL) OAuthToken(org.eclipse.che.api.auth.shared.dto.OAuthToken) HttpURLConnection(java.net.HttpURLConnection) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) GitHubKey(org.eclipse.che.plugin.github.shared.GitHubKey) SimpleDateFormat(java.text.SimpleDateFormat)

Example 83 with SimpleDateFormat

use of java.text.SimpleDateFormat in project jetty.project by eclipse.

the class RFC2616BaseTest method assertDate.

protected void assertDate(String msg, Calendar expectedTime, long actualTime) {
    SimpleDateFormat sdf = new SimpleDateFormat("EEEE, d MMMM yyyy HH:mm:ss:SSS zzz");
    sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
    String actual = sdf.format(new Date(actualTime));
    String expected = sdf.format(expectedTime.getTime());
    Assert.assertEquals(msg, expected, actual);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 84 with SimpleDateFormat

use of java.text.SimpleDateFormat in project jetty.project by eclipse.

the class DateTag method doAfterBody.

public int doAfterBody() throws JspException {
    try {
        SimpleDateFormat format = new SimpleDateFormat(body.getString());
        format.setTimeZone(TimeZone.getTimeZone(tz));
        body.getEnclosingWriter().write(format.format(new Date()));
        return SKIP_BODY;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new JspTagException(ex.toString());
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) JspTagException(javax.servlet.jsp.JspTagException) Date(java.util.Date) JspException(javax.servlet.jsp.JspException) JspTagException(javax.servlet.jsp.JspTagException)

Example 85 with SimpleDateFormat

use of java.text.SimpleDateFormat in project xLog by elvishew.

the class DateFileNameGenerator method generateFileName.

/**
   * Generate a file name which represent a specific date.
   */
@Override
public String generateFileName(int logLevel, long timestamp) {
    SimpleDateFormat sdf = mLocalDateFormat.get();
    sdf.setTimeZone(TimeZone.getDefault());
    return sdf.format(new Date(timestamp));
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)2847 Date (java.util.Date)1590 ParseException (java.text.ParseException)463 DateFormat (java.text.DateFormat)425 Calendar (java.util.Calendar)307 Test (org.junit.Test)305 ArrayList (java.util.ArrayList)232 File (java.io.File)230 IOException (java.io.IOException)185 GregorianCalendar (java.util.GregorianCalendar)139 HashMap (java.util.HashMap)121 Locale (java.util.Locale)70 DateField (edu.uci.ics.textdb.api.field.DateField)64 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)64 IField (edu.uci.ics.textdb.api.field.IField)64 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)64 StringField (edu.uci.ics.textdb.api.field.StringField)63 TextField (edu.uci.ics.textdb.api.field.TextField)63 Map (java.util.Map)63 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)61