List of usage examples for org.joda.time DateTime toString
public String toString(String pattern)
From source file:com.wealdtech.utils.RangeFormatter.java
License:Open Source License
private String doFormat(final DateTime datetime, final Details formatDetails) { final DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); boolean started = false; if (style != Style.TIME_ONLY) { if (formatDetails.showDayOfWeek) { if (style == Style.NORMAL) { builder.appendDayOfWeekShortText(); } else { builder.appendDayOfWeekText(); }// w w w. j a va 2 s . c o m started = true; } if (formatDetails.showDayOfMonth) { if (started) { builder.appendLiteral(' '); } builder.appendDayOfMonth(1); started = true; } if (formatDetails.showMonthOfYear) { if (started) { builder.appendLiteral(' '); } if (style == Style.NORMAL) { builder.appendMonthOfYearShortText(); } else { builder.appendMonthOfYearText(); } started = true; } if (formatDetails.showYear) { if (started) { builder.appendLiteral(' '); } builder.appendYear(4, 4); started = true; } } if (formatDetails.showTime) { if (started) { builder.appendLiteral(' '); } builder.appendHourOfDay(2); builder.appendLiteral(':'); builder.appendMinuteOfHour(2); started = true; } if (started) { return datetime.toString(builder.toFormatter().withLocale(locale)); } else { return null; } }
From source file:com.weavers.duqhan.util.GoogleBucketFileUploader.java
public static String uploadProductImage(MultipartFile file, Long productId) { InputStream targetStream = null; String imgUrl = "failure"; if (file != null) { try {//from ww w .j a va 2s.c o m GoogleBucketFileUploader fileUploader = new GoogleBucketFileUploader(); Storage storage = fileUploader.authentication(); targetStream = file.getInputStream(); if (targetStream != null) { DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS"); DateTime dt = DateTime.now(DateTimeZone.UTC); String dtString = dt.toString(dtf); final String fileName = "img_" + productId.toString() + dtString + ".jpg"; // the inputstream is closed by default, so we don't need to close it here BlobInfo blobInfo = storage.create( BlobInfo.newBuilder(PRODUCT_BUCKET_NAME, fileName).setContentType("image/jpeg") // Modify access list to allow all users with link to read file .setAcl(new ArrayList<>( Arrays.asList(Acl.of(Acl.User.ofAllUsers(), Acl.Role.OWNER)))) .build(), targetStream); // return the public view link // System.out.println("https://storage.googleapis.com/duqhan-users/" + blobInfo.getName()); imgUrl = "https://storage.googleapis.com/duqhan-images/" + blobInfo.getName(); } } catch (IOException ex) { Logger.getLogger(GoogleBucketFileUploader.class.getName()).log(Level.SEVERE, null, ex); } } return imgUrl; }
From source file:com.weavers.duqhan.util.GoogleBucketFileUploader.java
public static String uploadProductImage(String url, Long productId) { String imgUrl = "failure"; try {/* ww w .j a v a 2 s .c om*/ GoogleBucketFileUploader fileUploader = new GoogleBucketFileUploader(); Storage storage = fileUploader.authentication(); InputStream input = new URL(url).openStream(); if (input != null) { DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS"); DateTime dt = DateTime.now(DateTimeZone.UTC); String dtString = dt.toString(dtf); final String fileName = "img_" + productId.toString() + dtString + ".jpg"; // the inputstream is closed by default, so we don't need to close it here BlobInfo blobInfo = storage.create( BlobInfo.newBuilder(PRODUCT_BUCKET_NAME, fileName).setContentType("image/jpeg") // Modify access list to allow all users with link to read file .setAcl(new ArrayList<>( Arrays.asList(Acl.of(Acl.User.ofAllUsers(), Acl.Role.OWNER)))) .build(), input); // return the public view link imgUrl = "https://storage.googleapis.com/" + PRODUCT_BUCKET_NAME + "/" + blobInfo.getName(); // imgUrl = "https://storage.googleapis.com/duqhan-images/" + blobInfo.getName(); } } catch (Exception ex) { Logger.getLogger(GoogleBucketFileUploader.class.getName()).log(Level.SEVERE, null, ex); } return imgUrl; }
From source file:com.wookler.server.common.utils.TimeUtils.java
License:Apache License
/** * Get a formatted string for the current date/time. * /*from ww w .ja va 2s . c o m*/ * @param format * - Date/Time format. * @return */ public static String now(String format) { DateTime dt = new DateTime(); return dt.toString(format); }
From source file:com.wookler.server.river.MessageBlockBackup.java
License:Apache License
private String windowdir(long timestamp) { StringBuffer b = new StringBuffer(destination.getAbsolutePath()); DateTime t = new DateTime(timestamp); b.append(t.toString(Constants.DIR_DATETIME_FORMAT)); return b.toString(); }
From source file:com.yahoo.bard.webservice.sql.helper.TimestampUtils.java
License:Apache License
/** * Creates a timestamp from a DateTime./*from w ww. j a v a 2 s. c o m*/ * * @param dateTime The dateTime to create the timestamp at. * * @return the timestamp created from this dateTime. */ public static Timestamp timestampFromDateTime(DateTime dateTime) { return Timestamp.valueOf(dateTime.toString("yyyy-MM-dd HH:mm:ss.S")); }
From source file:com.zfer.kit.DateKit.java
License:Apache License
/** * ???/*from w w w .j ava 2s .c o m*/ * * @return currentDate */ public static String getCurrentDate() { DateTime dt = new DateTime(); return dt.toString(DATE_FORMAT); }
From source file:com.zfer.kit.DateKit.java
License:Apache License
/** * ???/* w ww. j a v a 2s.c o m*/ * * @return currentDateTime */ public static String getCurrentDateTime() { DateTime dt = new DateTime(); return dt.toString(DATE_TIME_FORMAT); }
From source file:com.zfer.kit.DateKit.java
License:Apache License
/** * date to string./*w ww . jav a2 s .c om*/ * * @param date input date object * @param format fomat pattern string * @return date to string */ public static String toStr(Date date, String format) { if (date == null) { return ""; } DateTime dt = new DateTime(date); return dt.toString(format); }
From source file:com.zfer.kit.DateKit.java
License:Apache License
/** * ?preDay./*w w w .j ava 2s . c om*/ * * @param dateStr like 2014-09-23 ISO8601? * @return preDay the pre of day */ public static String getPreDay(String dateStr) { if (StrKit.isBlank(dateStr)) { return ""; } DateTime dt = new DateTime(dateStr).minusDays(1); return dt.toString(DATE_FORMAT); }