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;
}
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));
}
}
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);
}
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());
}
}
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));
}
Aggregations