本文整理匯總了Java中org.apache.commons.lang3.time.DateFormatUtils.formatUTC方法的典型用法代碼示例。如果您正苦於以下問題:Java DateFormatUtils.formatUTC方法的具體用法?Java DateFormatUtils.formatUTC怎麽用?Java DateFormatUtils.formatUTC使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang3.time.DateFormatUtils
的用法示例。
在下文中一共展示了DateFormatUtils.formatUTC方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fetch
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
@Override
public List<JsonObject> fetch() throws IOException {
List<JsonObject> filtered = new ArrayList<JsonObject>();
JsonArray notifications = this.request().fetch()
.as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_OK)
.as(JsonResponse.class).json().readArray();
this.lastReadAt = DateFormatUtils.formatUTC(
new Date(System.currentTimeMillis()),
"yyyy-MM-dd'T'HH:mm:ss'Z'"
);
log.info("Found " + notifications.size() + " new notifications!");
if(notifications.size() > 0) {
List<JsonObject> unfiltered = new ArrayList<JsonObject>();
for(int i=0; i<notifications.size(); i++) {
unfiltered.add(notifications.getJsonObject(i));
}
filtered = this.reason.filter(unfiltered);
}
return filtered;
}
示例2: toJsonObject
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* Return the <code>JsonObject</code> representation of the <code>DeviceLocation</code> object.
* @return JsonObject object
*/
public JsonObject toJsonObject() {
JsonObject json = new JsonObject();
json.addProperty(this.latitude.getResourceName(), latitude.getValue());
json.addProperty(this.longitude.getResourceName(), longitude.getValue());
if(elevation != null) {
json.addProperty(this.elevation.getResourceName(), elevation.getValue());
}
String utcTime = DateFormatUtils.formatUTC(measuredDateTime.getValue(),
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
json.addProperty(this.measuredDateTime.getResourceName(), utcTime);
if(accuracy != null) {
json.addProperty(this.accuracy.getResourceName(), accuracy.getValue());
}
return json;
}
示例3: humanizeTimestamp
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
public String humanizeTimestamp(long timestamp) {
if (taskDatePattern.isPresent() && timeZone.isPresent()) {
return DateFormatUtils.format(timestamp, taskDatePattern.get(), timeZone.get());
} else if (taskDatePattern.isPresent()) {
return DateFormatUtils.formatUTC(timestamp, taskDatePattern.get());
} else if (timeZone.isPresent()) {
return DateFormatUtils.format(timestamp, DEFAULT_TIMESTAMP_FORMAT, timeZone.get());
} else {
return DateFormatUtils.format(timestamp, DEFAULT_TIMESTAMP_FORMAT);
}
}
示例4: RtNotifications
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* Ctor.
* @param res Reason.
* @param token Token used with this request.
* @param edp String endpoint.
*/
public RtNotifications(Reason res, String token, String edp) {
super(token, edp);
this.reason = res;
this.lastReadAt = DateFormatUtils.formatUTC(
new Date(System.currentTimeMillis()),
"yyyy-MM-dd'T'HH:mm:ss'Z'"
);
}
示例5: updateLocation
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* Update the location of the device. This method converts the
* date in the required format. The caller just need to pass the date in java.util.Date format
*
* @param latitude Latitude in decimal degrees using WGS84
* @param longitude Longitude in decimal degrees using WGS84
* @param elevation Elevation in meters using WGS84
* @param measuredDateTime When the location information is retrieved
* @param accuracy Accuracy of the position in meters
*
* @return code indicating whether the update is successful or not
* (200 means success, otherwise unsuccessful)
*/
public int updateLocation(Double latitude, Double longitude, Double elevation, Date measuredDateTime, Double accuracy) {
final String METHOD = "updateLocation";
JsonObject jsonData = new JsonObject();
JsonObject json = new JsonObject();
json.addProperty("longitude", longitude);
json.addProperty("latitude", latitude);
if(elevation != null) {
json.addProperty("elevation", elevation);
}
String utcTime = DateFormatUtils.formatUTC(measuredDateTime,
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
json.addProperty("measuredDateTime", utcTime);
if(accuracy != null) {
json.addProperty("accuracy", accuracy);
}
jsonData.add("d", json);
try {
JsonObject response = sendAndWait(client.getDMAgentTopic().getUpdateLocationTopic(),
jsonData, REGISTER_TIMEOUT_VALUE);
if (response != null ) {
return response.get("rc").getAsInt();
}
} catch (MqttException e) {
LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString());
}
return 0;
}
示例6: addLog
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* The Log message that needs to be added to the Watson IoT Platform.
*
* @param message The Log message that needs to be added to the Watson IoT Platform.
* @param timestamp The Log timestamp
* @param severity The Log severity
* @param data The optional diagnostic string data -
* The library will encode the data in base64 format as required by the Platform
* @return code indicating whether the update is successful or not
* (200 means success, otherwise unsuccessful)
*/
public int addLog(String message, Date timestamp, LogSeverity severity, String data) {
final String METHOD = "addLog";
JsonObject jsonData = new JsonObject();
JsonObject log = new JsonObject();
log.add("message", new JsonPrimitive(message));
log.add("severity", new JsonPrimitive(severity.getSeverity()));
String utcTime = DateFormatUtils.formatUTC(timestamp,
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
log.add("timestamp", new JsonPrimitive(utcTime));
if(data != null) {
byte[] encodedBytes = Base64.encodeBase64(data.getBytes());
log.add("data", new JsonPrimitive(new String(encodedBytes)));
}
jsonData.add("d", log);
try {
JsonObject response = sendAndWait(client.getDMAgentTopic().getAddDiagLogTopic(),
jsonData, REGISTER_TIMEOUT_VALUE);
if (response != null ) {
return response.get("rc").getAsInt();
}
} catch (MqttException e) {
LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString());
}
return 0;
}
示例7: toJsonObject
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* Returns the value in Json Format
*/
@Override
public JsonElement toJsonObject() {
String utcTime = DateFormatUtils.formatUTC(getValue(),
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
return (JsonElement) new JsonPrimitive(utcTime);
}
示例8: push
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
@Override
public String push(final Events events) throws IOException {
final Github github = new RtGithub(this.config.getString("token"));
final String since = DateFormatUtils.formatUTC(
DateUtils.addMinutes(new Date(), -Tv.THREE),
"yyyy-MM-dd'T'HH:mm:ss'Z'"
);
final Request req = github.entry()
.uri().path("/notifications").back();
final Iterable<JsonObject> list = new RtPagination<>(
req.uri().queryParam("participating", "true")
.queryParam("since", since)
.queryParam("all", Boolean.toString(true))
.back(),
RtPagination.COPYING
);
final Collection<String> done = new LinkedList<>();
for (final JsonObject event : AgGithub.safe(list)) {
final String reason = event.getString("reason");
if (!"mention".equals(reason)) {
continue;
}
this.push(github, event, events);
done.add(event.getString("id"));
}
req.uri()
.queryParam("last_read_at", since).back()
.method(Request.PUT)
.body().set("{}").back()
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_RESET);
if (!done.isEmpty()) {
Logger.info(
this, "%d GitHub events for @%s processed: %s",
done.size(), github.users().self().login(), done
);
}
return String.format(
"%d events for @%s at %s",
done.size(), github.users().self().login(),
DateFormatUtils.formatUTC(new Date(), "yyyy-MM-dd HH:mm:ss")
);
}
示例9: addDiagnosticErrorCode
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* Adds an error code to the list of error codes for the device.
* The list may be pruned as the new entry is added.
*
* <p> Refer to
* <a href="https://docs.internetofthings.ibmcloud.com/swagger/v0002.html#!/Device_Diagnostics/post_device_types_typeId_devices_deviceId_diag_errorCodes">link</a>
* for more information about the schema to be used </p>
*
* @param deviceType String which contains device type
* @param deviceId String which contains device id
* @param errorcode ErrorCode to be added in integer format
* @param date current date (can be null)
*
* @return boolean containing the status of the add operation.
*
* @throws IoTFCReSTException Failure in adding the error codes
*/
public boolean addDiagnosticErrorCode(String deviceType, String deviceId,
int errorcode, Date date) throws IoTFCReSTException {
JsonObject ec = new JsonObject();
ec.addProperty("errorCode", errorcode);
if(date == null) {
date = new Date();
}
String utcTime = DateFormatUtils.formatUTC(date,
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
ec.addProperty("timestamp", utcTime);
return addDiagnosticErrorCode(deviceType, deviceId, ec);
}
示例10: updateDeviceLocation
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* Update the location of the device connected through the Gateway. This method converts the
* date in the required format. The caller just need to pass the date in java.util.Date format.
*
* @param typeId The device type of the device connected to the Gateway
* @param deviceId The deviceId of the device connected to the Gateway
* @param latitude Latitude in decimal degrees using WGS84
* @param longitude Longitude in decimal degrees using WGS84
* @param elevation Elevation in meters using WGS84
* @param measuredDateTime Date of location measurement
* @param updatedDateTime Date of the update to the device information
* @param accuracy Accuracy of the position in meters
*
* @return code indicating whether the update is successful or not
* (200 means success, otherwise unsuccessful)
*/
public int updateDeviceLocation(String typeId,
String deviceId,
Double latitude,
Double longitude,
Double elevation,
Date measuredDateTime,
Date updatedDateTime,
Double accuracy) {
final String METHOD = "updateLocation";
String key = typeId + ':' + deviceId;
ManagedGatewayDevice mc = (ManagedGatewayDevice) this.devicesMap.get(key);
if(mc == null) {
LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD,
"The device is not a managed device, so can not send the request");
return -1;
}
JsonObject jsonData = new JsonObject();
JsonObject json = new JsonObject();
json.addProperty("longitude", longitude);
json.addProperty("latitude", latitude);
if(elevation != null) {
json.addProperty("elevation", elevation);
}
String utcTime = DateFormatUtils.formatUTC(measuredDateTime,
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
json.addProperty("measuredDateTime", utcTime);
if(updatedDateTime != null) {
utcTime = DateFormatUtils.formatUTC(updatedDateTime,
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
json.addProperty("updatedDateTime", utcTime);
}
if(accuracy != null) {
json.addProperty("accuracy", accuracy);
}
jsonData.add("d", json);
try {
JsonObject response = sendAndWait(mc.getDMAgentTopic().getUpdateLocationTopic(),
jsonData, REGISTER_TIMEOUT_VALUE);
if (response != null ) {
return response.get("rc").getAsInt();
}
} catch (MqttException e) {
LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString());
}
return 0;
}
示例11: formatDate
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* @param date
*/
protected static String formatDate(Calendar date) {
return DateFormatUtils.formatUTC(date.getTimeInMillis(), "yyyy-MM-dd'T'HH:mm:ss'Z'"); //$NON-NLS-1$
}
示例12: formatDateWithMillis
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* @param date
*/
protected static String formatDateWithMillis(Calendar date) {
return DateFormatUtils.formatUTC(date.getTimeInMillis(), "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); //$NON-NLS-1$
}
示例13: TimeUtils
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* 使用日期對象構造時間
*
* @param date
*/
public TimeUtils(Date date) {
this(DateFormatUtils.formatUTC(date, "HH:mm:ss"));
}
示例14: TimeUtils
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* 使用日期對象構造時間
*
* @param date
*/
public TimeUtils(Date date) {
this(DateFormatUtils.formatUTC(date, "HH:mm:ss"));
}
示例15: TimeUtils
import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* 使用日期對象構造時間
* @param date
*/
public TimeUtils(Date date){
this(DateFormatUtils.formatUTC(date, "HH:mm:ss"));
}