当前位置: 首页>>代码示例>>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;未经允许,请勿转载。