本文整理汇总了Java中org.joda.time.DateTime.toString方法的典型用法代码示例。如果您正苦于以下问题:Java DateTime.toString方法的具体用法?Java DateTime.toString怎么用?Java DateTime.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.DateTime
的用法示例。
在下文中一共展示了DateTime.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTime
import org.joda.time.DateTime; //导入方法依赖的package包/类
@NonNull
private static String getTime(DateTime msgTime) {
int hourOfDay = msgTime.getHourOfDay();
String when;
if (hourOfDay >= 18) {//18-24
when = "晚上";
} else if (hourOfDay >= 13) {//13-18
when = "下午";
} else if (hourOfDay >= 11) {//11-13
when = "中午";
} else if (hourOfDay >= 5) {//5-11
when = "早上";
} else {//0-5
when = "凌晨";
}
return when + " " + msgTime.toString("hh:mm");
}
示例2: interpreterDateTest
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Test
public void interpreterDateTest() throws Exception {
final String[] colNames = {"col1"};
final TypeProtos.MajorType[] colTypes = {Types.optional(TypeProtos.MinorType.INT)};
final String expressionStr = "now()";
final BitControl.PlanFragment planFragment = BitControl.PlanFragment.getDefaultInstance();
final QueryContextInformation queryContextInfo = planFragment.getContext();
final int timeZoneIndex = queryContextInfo.getTimeZone();
final org.joda.time.DateTimeZone timeZone = org.joda.time.DateTimeZone.forID(org.apache.drill.exec.expr.fn.impl.DateUtility.getTimeZone(timeZoneIndex));
final org.joda.time.DateTime now = new org.joda.time.DateTime(queryContextInfo.getQueryStartTime(), timeZone);
final long queryStartDate = now.getMillis();
final TimeStampHolder out = new TimeStampHolder();
out.value = queryStartDate;
final ByteBuffer buffer = ByteBuffer.allocate(12);
buffer.putLong(out.value);
final long l = buffer.getLong(0);
final DateTime t = new DateTime(l);
final String[] expectedFirstTwoValues = {t.toString(), t.toString()};
doTest(expressionStr, colNames, colTypes, expectedFirstTwoValues, planFragment);
}
示例3: dateToStr
import org.joda.time.DateTime; //导入方法依赖的package包/类
public static String dateToStr(Date date, String formatStr) {
if (date == null) {
return StringUtils.EMPTY;
}
DateTime dateTime = new DateTime(date);
return dateTime.toString(formatStr);
}
示例4: dateToStr
import org.joda.time.DateTime; //导入方法依赖的package包/类
public static String dateToStr(Date date,String formatStr){
if(date == null){
return StringUtils.EMPTY;
}
DateTime dateTime = new DateTime(date);
return dateTime.toString(formatStr);
}
示例5: getMsgFormatTime
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 得到仿微信日期格式输出
*
* @param msgTimeMillis
* @return
*/
public static String getMsgFormatTime(long msgTimeMillis) {
DateTime nowTime = new DateTime();
// LogUtils.sf("nowTime = " + nowTime);
DateTime msgTime = new DateTime(msgTimeMillis);
// LogUtils.sf("msgTime = " + msgTime);
int days = Math.abs(Days.daysBetween(msgTime, nowTime).getDays());
// LogUtils.sf("days = " + days);
if (days < 1) {
//早上、下午、晚上 1:40
return getTime(msgTime);
} else if (days == 1) {
//昨天
return "昨天 " + getTime(msgTime);
} else if (days <= 7) {
//星期
switch (msgTime.getDayOfWeek()) {
case DateTimeConstants.SUNDAY:
return "周日 " + getTime(msgTime);
case DateTimeConstants.MONDAY:
return "周一 " + getTime(msgTime);
case DateTimeConstants.TUESDAY:
return "周二 " + getTime(msgTime);
case DateTimeConstants.WEDNESDAY:
return "周三 " + getTime(msgTime);
case DateTimeConstants.THURSDAY:
return "周四 " + getTime(msgTime);
case DateTimeConstants.FRIDAY:
return "周五 " + getTime(msgTime);
case DateTimeConstants.SATURDAY:
return "周六 " + getTime(msgTime);
}
return "";
} else {
//12月22日
return msgTime.toString("MM月dd日 " + getTime(msgTime));
}
}
示例6: setDateTimeText
import org.joda.time.DateTime; //导入方法依赖的package包/类
public void setDateTimeText(DateTime dateTime) {
String timeText = "";
if (dateTime != null) {
timeText = dateTime.toString(DATETIME_FORMAT);
}
mDateTimeText.setText(timeText);
}
示例7: showHabitEventDate
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Test
public void showHabitEventDate() throws Exception {
DateTime testDate = new DateTime(1512199000000l);
String dateString = testDate.toString("d MMM");
onData(anything())
.inAdapterView(withId(R.id.list))
.atPosition(0)
.onChildView(withId(R.id.myHabitEventListItemStartDate))
.check(matches(withText(dateString)));
}
示例8: onCurrentMonthChanged
import org.joda.time.DateTime; //导入方法依赖的package包/类
private void onCurrentMonthChanged(DateTime currentMonth) {
String month = currentMonth.toString("MMMMM", Locale.getDefault());
if (view != null && !TextUtils.isEmpty(month)) {
String formattedMonth = month.substring(0, 1).toUpperCase(Locale.getDefault()) + month.substring(1);
view.onCurrentMonthChanged(formattedMonth);
}
}
示例9: removeTimeZoneIfRequired
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* Removes the time zone for a given date if the Calendar Entry is an all day event
*
* @return ISO 8601 formatted date String if datePattern is null
*/
protected String removeTimeZoneIfRequired(Date date, Boolean isAllDay, Boolean removeTimezone, String datePattern)
{
if (removeTimezone)
{
DateTime dateTime = new DateTime(date, DateTimeZone.UTC);
if (null == datePattern)
{
return dateTime.toString((isAllDay) ? (ALL_DAY_DATETIME_FORMATTER) : (ISODateTimeFormat.dateTime()));
}
else
{
// For Legacy Dates and Times.
return dateTime.toString(DateTimeFormat.forPattern(datePattern));
}
}
// This is for all other cases, including the case, when UTC time zone is configured
if (!isAllDay && (null == datePattern))
{
return ISO8601DateFormat.format(date);
}
DateFormat simpleDateFormat = new SimpleDateFormat((null != datePattern) ? (datePattern) : (ALL_DAY_DATETIME_PATTERN));
return simpleDateFormat.format(date);
}
示例10: convertDateLiteral
import org.joda.time.DateTime; //导入方法依赖的package包/类
private String convertDateLiteral(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
try {
Object value = lit.getValue();
if (value instanceof XSDDateTime) {
Calendar calendar = ((XSDDateTime) value).asCalendar();
if (dt.equals(XSDDatatype.XSDgMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgMonthDay)) {
s = calendar.get(Calendar.DAY_OF_MONTH)
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgYearMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL) + " "
+ calendar.get(Calendar.YEAR);
} else if (dt.equals(XSDDatatype.XSDgYear)) {
s = "" + calendar.get(Calendar.YEAR);
} else {
s = calendar.get(Calendar.DAY_OF_MONTH) + " "
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL) + " "
+ calendar.get(Calendar.YEAR);
// dateFormat.format(calendar.getTime());
}
}
} catch (DatatypeFormatException | IllegalDateTimeFieldException e) {
logger.error("Conversion of date literal " + lit + " failed. Reason: " + e.getMessage());
// fallback
// DateTime time = ISODateTimeFormat.dateTime
DateTime time;
try {
time = ISODateTimeFormat.dateTimeParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd MMMM YYYY", FRENCH_LOCAL);
} catch (Exception e1) {
try {
time = ISODateTimeFormat.localDateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd MMMM YYYY", FRENCH_LOCAL);
} catch (Exception e2) {
e2.printStackTrace();
time = ISODateTimeFormat.dateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd MMMM YYYY", FRENCH_LOCAL);
}
}
}
return s;
}
示例11: toString
import org.joda.time.DateTime; //导入方法依赖的package包/类
public static String toString(@NonNull DateTime value) {
return value.toString();
}
示例12: encodeTimestamp
import org.joda.time.DateTime; //导入方法依赖的package包/类
public static String encodeTimestamp(long partitionDurationMs, String pathFormat, String timeZoneString, long timestamp) {
DateTimeZone timeZone = DateTimeZone.forID(timeZoneString);
DateTimeFormatter formatter = DateTimeFormat.forPattern(pathFormat).withZone(timeZone);
DateTime partition = new DateTime(getPartition(partitionDurationMs, timestamp, timeZone));
return partition.toString(formatter);
}
示例13: convertDateLiteral
import org.joda.time.DateTime; //导入方法依赖的package包/类
private String convertDateLiteral(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
try {
Object value = lit.getValue();
if (value instanceof XSDDateTime) {
Calendar calendar = ((XSDDateTime) value).asCalendar();
if (dt.equals(XSDDatatype.XSDgMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgMonthDay)) {
s = calendar.get(Calendar.DAY_OF_MONTH)
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgYearMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL) + " "
+ calendar.get(Calendar.YEAR);
} else if (dt.equals(XSDDatatype.XSDgYear)) {
s = "" + calendar.get(Calendar.YEAR);
} else {
s = calendar.get(Calendar.DAY_OF_MONTH) + " de "
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL) + " de "
+ calendar.get(Calendar.YEAR);
// dateFormat.format(calendar.getTime());
}
}
} catch (DatatypeFormatException | IllegalDateTimeFieldException e) {
logger.error("Conversion of date literal " + lit + " failed. Reason: " + e.getMessage());
// fallback
// DateTime time = ISODateTimeFormat.dateTime
DateTime time;
try {
time = ISODateTimeFormat.dateTimeParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd 'de' MMMM 'de' YYYY", PORTUGUESE_LOCAL);
} catch (Exception e1) {
try {
time = ISODateTimeFormat.localDateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd 'de' MMMM 'de' YYYY", PORTUGUESE_LOCAL);
} catch (Exception e2) {
e2.printStackTrace();
time = ISODateTimeFormat.dateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd 'de' MMMM 'de' YYYY", PORTUGUESE_LOCAL);
}
}
}
return s;
}
示例14: dateAsString
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* Formattage des dates en texte à afficher dans l'IHM
* @param date
* @return
*/
public static String dateAsString(final DateTime date) {
return (date != null) ? (dateFormatter != null) ? dateFormatter.print(date) : date.toString() : null;
}
示例15: time2Str
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 将时间转换为指定格式的字符串
*
* @param date
* @param pattern
* @return
*/
public static String time2Str(Date date, String pattern) {
DateTime dateTime = new DateTime(date);
return dateTime.toString(pattern);
}