根据他们的网站,DUration类实现了ISO 8601
http://en.wikipedia.org/wiki/ISO_8601#Durations
但让我们看一个例子.持续时间为14分钟和51秒.在ISO 8601中,这些代码是等效的:
System.out.println("bug "+new Duration("PT14M51S"));
System.out.println("NO bug "+new Duration("PT891S");
Run Code Online (Sandbox Code Playgroud)
PT14M51S是postgresql数据库的真正摘录并且正确.joda-time api只是将所有内容转换为秒为什么?它似乎不知道任何东西比关键字S(theres Y,M,D ...)
提前致谢
我在我的scala代码中使用joda时间库.我的代码如下.
val dt:DateTime = new DateTime()
val dtf:DateTimeFormatter = DateTimeFormat.forPattern("yyyy-mm-dd")
return dtf.print(dt.minusDays(1))
Run Code Online (Sandbox Code Playgroud)
假设当前日期是2011年3月11日,上面的代码应该返回字符串2011-03-10,但我得到的输出是 2011-52-10
什么可能导致这个问题?
请帮助谢谢
鉴于DateTime
2011年3月31日的对象和此代码:
DateTime temp1 = new DateTime(2011, 3, 31, 12, 0, 0, 0);
DateTime temp2 = temp1.plusMonths(1);
DateTime temp3 = temp2.plusMonths(1);
Run Code Online (Sandbox Code Playgroud)
执行后
temp1 = 2011-03-31T12:00:00.000+02:00
temp2 = 2011-04-30T12:00:00.000+02:00
temp3 = 2011-05-30T12:00:00.000+02:00
Run Code Online (Sandbox Code Playgroud)
temp3在这里错了.
这是正确的吗?我做错了吗?
有没有办法从时区字符串表示创建(joda)DateTimeZone对象,如"EDT"或"+0330"?
我正在尝试使用Joda-Time将我的应用程序用户输入的日期转换为ISO 8601格式,所以我使用以下代码但是我收到错误:
String oldDate = "05/05/2013";
DateTime oldD = DateTime.parse(oldDate);
DateTimeFormatter OldDFmt = ISODateTimeFormat.dateTime();
String str = OldDFmt.print(oldD);
System.out.println(str);
Run Code Online (Sandbox Code Playgroud)
但我总是得到错误:
org.springframework.web.util.NestedServletException:请求处理失败; 嵌套异常是java.lang.IllegalArgumentException:格式无效:"05/05/2013"格式错误为"/ 05/2013"
有人可以帮忙告诉我这里做错了什么吗?谢谢.
如何判断joda-time
自动检测24小时字符串并相应地解析它们?
DateTimeFormat.forPattern("YYYYMMDDhhmm").parseDateTime("201410171500");
Run Code Online (Sandbox Code Playgroud)
结果是:
org.joda.time.IllegalFieldValueException: Cannot parse "201410171500": Value 50 for clockhourOfHalfday must be in the range [1,12]
at org.joda.time.field.FieldUtils.verifyValueBounds(FieldUtils.java:234)
at org.joda.time.field.ZeroIsMaxDateTimeField.set(ZeroIsMaxDateTimeField.java:86)
at org.joda.time.format.DateTimeParserBucket$SavedField.set(DateTimeParserBucket.java:568)
at org.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeParserBucket.java:447)
at org.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeParserBucket.java:411)
at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:882)
Run Code Online (Sandbox Code Playgroud)
顺便说一句,这很奇怪:以下工作没有错误:
DateTimeFormat.forPattern("YYYYMMDDHH").parseDateTime("2014101715");
所以我有2个日期选择器用于开始和结束时间,它们返回DateTime.
我需要以"小时小时分钟"的格式计算这两次之间的持续时间,例如,"1小时30分钟".如果有天差,它将显示"24小时",因此我们使用小时而不是天.
我遇到的问题是,无论我如何工作,如果用户提前选择一个月,它就会中断.他们永远不应该选择一个月,但可以选择.
我收到此错误:
java.lang.UnsupportedOperationException: Unable to normalize as PeriodType is missing either years or months but period has a month/year amount: P1M3W6DT1H
at org.joda.time.Period.normalizedStandard(Period.java:1640)
Run Code Online (Sandbox Code Playgroud)
我的代码是:
Period durationHoursAndMinutes = new Period(startDate.toLocalDateTime(), endDate.toLocalDateTime()).normalizedStandard(PeriodType.time());
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendHours()
.appendSuffix(getResources().getString(R.string.mytrips_tripview_rail_waitTime_hr))
.appendSeparator(" ")
.appendMinutes()
.appendSuffix(getResources().getString(R.string.mytrips_tripview_rail_waitTime_min))
.toFormatter();
if(durationHoursAndMinutes.getMinutes() > 0){
return formatter.print(durationHoursAndMinutes);
}else {
return null;
}
Run Code Online (Sandbox Code Playgroud)
我查看了PeriodType的代码,它说如果月份!= 0则抛出异常,它不会.只是想知道我是否有办法解决这个问题.谢谢你的帮助
大家,早安.
我想帮助您了解如何使用1.2.1.1版本的Joda Time完成org.joda.time.DateTime到java.util.Date的转换.
为何选择Joda 1.2.1.1?因为目前我只能使用这个版本的Joda"不幸".
我的测试>
System.out.println("JODA Version : 2.8.2 - UTC TIME to Date " + new DateTime().withZone(DateTimeZone.UTC).toLocalDateTime().toDate());;
System.out.println("JODA Version : 1.2.1.1 - UTC TIME to Date " + new DateTime().withZone(DateTimeZone.UTC).toDate());;
JODA Version : 2.8.2 - UTC TIME to Date Fri Sep 18 17:34:36 BRT 2015
JODA Version : 1.2.1.1 - UTC TIME to Date Fri Sep 18 14:34:36 BRT 2015
Run Code Online (Sandbox Code Playgroud)
我的问题是在版本1.2.1.1中,日期在我的本地设置上,在这个版本中没有toLocalDateTime()方法.
我会请求您的帮助和经验,以便在JODA版本:1.2.1.1中发现执行此转换的最佳实践
如何执行此转换为小时:分钟:UTC这个旧版JODA的第二个?
我研究了很多,看到一些人这样说会是一个好习惯吗?
public static Date converterDateTimeToUTCDate(final DateTime dateTime) throws ParseException {
DateTime dat = dateTime.withZone(DateTimeZone.UTC);
return …
Run Code Online (Sandbox Code Playgroud) 嗨我有一个按Arraylist
日期顺序排列的日期.日期是这种格式yyyy-MM-dd
.现在我想找出最长的连续子序列Arraylist
.我已经在线检查了解决方案,但它们与int数组有关,我想查找日期数组.int数组的代码:
// Returns length of the longest contiguous subarray
int findLength(int arr[], int n)
{
int max_len = 1; // Initialize result
for (int i=0; i<n-1; i++)
{
// Initialize min and max for all subarrays starting with i
int mn = arr[i], mx = arr[i];
// Consider all subarrays starting with i and ending with j
for (int j=i+1; j<n; j++)
{
// Update min and max in this subarray if needed
mn …
Run Code Online (Sandbox Code Playgroud) 我已经采取了SOF和其他网站上给出的所有答案,并尝试这样做:
String fromDateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sssX").format(new DateTime().plusMonths(-6));
Run Code Online (Sandbox Code Playgroud)
但是我被给了例外:
线程"main"中的异常java.lang.IllegalArgumentException:无法将给定的Object格式化为Date
我究竟做错了什么?