當前位置: 首頁>>代碼示例>>Java>>正文


Java DateTime.toString方法代碼示例

本文整理匯總了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");
}
 
開發者ID:lo625090140,項目名稱:lqrwechatrongcloud,代碼行數:18,代碼來源:TimeUtils.java

示例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);
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:27,代碼來源:ExpressionInterpreterTest.java

示例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);
}
 
開發者ID:jeikerxiao,項目名稱:X-mall,代碼行數:8,代碼來源:DateTimeUtil.java

示例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);
}
 
開發者ID:wangshufu,項目名稱:mmall,代碼行數:8,代碼來源:DateTimeUtil.java

示例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));
        }
    }
 
開發者ID:lo625090140,項目名稱:lqrwechatrongcloud,代碼行數:44,代碼來源:TimeUtils.java

示例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);
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-android,代碼行數:8,代碼來源:EditToolsView.java

示例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)));
}
 
開發者ID:CMPUT301F17T13,項目名稱:cat-is-a-dog,代碼行數:13,代碼來源:HabitHistoryTest.java

示例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);
    }
}
 
開發者ID:MOLO17,項目名稱:CustomizableCalendar,代碼行數:8,代碼來源:CustomizableCalendarPresenterImpl.java

示例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);
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:34,代碼來源:AbstractCalendarWebScript.java

示例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;
}
 
開發者ID:dice-group,項目名稱:RDF2PT,代碼行數:47,代碼來源:LiteralConverterFrench.java

示例11: toString

import org.joda.time.DateTime; //導入方法依賴的package包/類
public static String toString(@NonNull DateTime value) {
  return value.toString();
}
 
開發者ID:DiUS,項目名稱:pact-workshop-android,代碼行數:4,代碼來源:DateHelper.java

示例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);
}
 
開發者ID:jiangxiluning,項目名稱:kafka-connect-hdfs,代碼行數:7,代碼來源:TimeUtils.java

示例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;
}
 
開發者ID:dice-group,項目名稱:RDF2PT,代碼行數:47,代碼來源:LiteralConverterPortuguese.java

示例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;
}
 
開發者ID:iapafoto,項目名稱:DicomViewer,代碼行數:9,代碼來源:SliderTimeComponent.java

示例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);
}
 
開發者ID:liuxuanhai,項目名稱:WeiXing_xmu-2016-MrCode,代碼行數:12,代碼來源:DateUtils.java


注:本文中的org.joda.time.DateTime.toString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。