本文整理汇总了Java中java.time.format.DateTimeFormatter.ofPattern方法的典型用法代码示例。如果您正苦于以下问题:Java DateTimeFormatter.ofPattern方法的具体用法?Java DateTimeFormatter.ofPattern怎么用?Java DateTimeFormatter.ofPattern使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.format.DateTimeFormatter
的用法示例。
在下文中一共展示了DateTimeFormatter.ofPattern方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendNotificationInternal
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
private void sendNotificationInternal(String email, String sipId, String result, Instant created, String templateName) {
try {
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd. MM. yyyy");
MimeMessageHelper message = generalMessage(email, appName, false);
Map<String, Object> params = generalArguments();
params.put("sipId", sipId);
params.put("result", result);
params.put("createdDate", Utils.extractDate(created).format(dateFormatter));
params.put("createdTime", Utils.extractTime(created).format(timeFormatter));
InputStream template = Utils.resource(templateName);
transformAndSend(template, params, message);
} catch (MessagingException | IOException ex) {
throw new GeneralException(ex);
}
}
示例2: onMessageReceived
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageReceivedEvent e) {
String content = e.getMessage().getContent();
//Never respond to a bot!
if (e.getAuthor().isBot())
return;
//Not the `Time` command
if (!content.equalsIgnoreCase(PREFIX + "Time")) {
return;
}
receivedcmd++;
DateTimeFormatter DTF = DateTimeFormatter.ofPattern("EE dd.MM.YYYY, HH:mm:ss | KK:mm:ss a");
OffsetDateTime now = OffsetDateTime.now();
e.getChannel().sendMessage("It's " + now.format(DTF)).queue();
executedcmd++;
}
示例3: generateProductIncrementName
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
private String generateProductIncrementName(int months){
String pattern = "%1s-%2s";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
LocalDate now = LocalDate.now();
LocalDate changeMonthDate = now.plusMonths(months);
String formattedChangeMonthDate = changeMonthDate.format(formatter);
String formattedNow = now.format(formatter);
return months < 0 ?
String.format(pattern,formattedChangeMonthDate,formattedNow) :
String.format(pattern,formattedNow ,formattedChangeMonthDate);
}
示例4: factory_parse_formatter_nullText
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d");
LocalDate.parse((String) null, f);
}
示例5: DateAsText
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
* Formats the milliseconds as date using the format and the locale.
* @param milliseconds Milliseconds to format as date.
* @param format The format to use.
* @param locale The locale to use for the format.
*/
public DateAsText(final long milliseconds, final String format,
final Locale locale) {
this(
ZonedDateTime.ofInstant(
Instant.ofEpochMilli(milliseconds), ZoneId.of("UTC")
),
DateTimeFormatter.ofPattern(format, locale)
);
}
示例6: DefectLog
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public DefectLog(Element e) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT);
this.number = Integer.valueOf(e.getAttributeValue(NUMBER_ELEMENT));
this.date = LocalDateTime.parse(e.getAttributeValue(DATE_ELEMENT), formatter);
this.type = PSP.Defect.valueOf(e.getAttributeValue(TYPE_ELEMENT));
this.injectPhase = PSP.Phase.valueOf(e.getAttributeValue(INJECT_ELEMENT));
this.removePhase = PSP.Phase.valueOf(e.getAttributeValue(REMOVE_ELEMENT));
this.fixMinutes = Integer.valueOf(e.getAttributeValue(FIX_ELEMENT));
this.reference = Integer.valueOf(e.getAttributeValue(REFERENCE_ELEMENT));
this.description = e.getAttributeValue(DESCRIPTION_ELEMENT);
this.element = e;
}
示例7: checkCustomConverter
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void checkCustomConverter() {
final CandlestickConverter converter = new CandlestickConverter(DateTimeFormatter.ofPattern("yyyy-MM-dd"),
DateTimeFormatter.ofPattern("HH:mm:ss"));
final Candlestick candlestick =
converter.convert("US33734X1928 [NA_ETF],60,2016-10-21,16:00:00,33.840000,33.960000,33.816000,33.927500,165000.000000");
assertEquals(candlestick.getTool(), "US33734X1928 [NA_ETF]");
assertEquals(candlestick.getCode(), "US33734X1928");
assertEquals(candlestick.getName(), "unknown");
assertEquals(candlestick.getDate(), LocalDate.parse("2016-10-21", converter.getDateFormatter()));
assertEquals(candlestick.getTime(), LocalTime.parse("16:00:00", converter.getTimeFormatter()));
}
示例8: transformToStr
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public static String transformToStr(long time) {
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(time), ZoneId.systemDefault());
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(FORMATTER);
return localDateTime.format(dateTimeFormatter);
}
示例9: getPrettyDate
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public static String getPrettyDate(LocalDate date) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d MMM", new Locale("es", "CO"));
return date.format(formatter).toUpperCase();
}
示例10: toString
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Override
public String toString(LocalDate date) {
DateTimeFormatter dtFormatter = DateTimeFormatter.ofPattern(getDateFormat());
String text = null;
if (date != null) {
text = dtFormatter.format(date);
}
return text;
}
示例11: test_pattern_StringLocale
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void test_pattern_StringLocale() {
DateTimeFormatter test = DateTimeFormatter.ofPattern("d MMM yyyy", Locale.UK);
assertEquals(test.format(LocalDate.of(2012, 6, 30)), "30 Jun 2012");
assertEquals(test.getLocale(), Locale.UK);
}
示例12: test_parseBest_secondOption
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void test_parseBest_secondOption() throws Exception {
DateTimeFormatter test = DateTimeFormatter.ofPattern("yyyy-MM-dd[ HH:mm[XXX]]");
TemporalAccessor result = test.parseBest("2011-06-30", ZonedDateTime::from, LocalDate::from);
assertEquals(result, LocalDate.of(2011, 6, 30));
}
示例13: factory_parse_formatter_nullText
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
MonthDay.parse((String) null, f);
}
示例14: main
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
LocalDateTime parse = LocalDateTime.parse("2012-10-01T09:45:00.000+02:00", formatter);
//localTime();
}
示例15: factory_parse_formatter
import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
@Test
public void factory_parse_formatter() {
DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s");
LocalTime test = LocalTime.parse("14 30 40", f);
assertEquals(test, LocalTime.of(14, 30, 40));
}