我正在使用Jackson(通过Spring MVC Annotations)将字段反序列化为java.util.Date来自JSON.POST看起来像 - {"enrollDate":"2011-09-28T00:00:00.000Z"},但是当对象由Spring&Jackson创建时,它将日期设置为"2011-09-27 20:00:00".
如何在杰克逊设置合适的时区? 或者,如果这不是问题,我如何从JSON消息发送EST?
使用Javascript/jQuery的:
var personDataView = { enrollDate : new Date($("#enrollDate").val()),
//...other members
};
$.postJSON('/some/path/', personDataView, function(data){
//... handle the response here
});
Run Code Online (Sandbox Code Playgroud)
JSON消息:
{"enrollDate":"2011-09-28T00:00:00.000Z"}
弹簧控制器:
@RequestMapping(value="/", method=RequestMethod.POST)
public @ResponseBody String saveProfile(@RequestBody personDataView persondataView, HttpServletRequest request)
{
//...dataView has a java.util.Date enrollDate field
//...other code
}
Run Code Online (Sandbox Code Playgroud) 我有问题SimpleDateFormat。
SimpleDateFormat dtfmt=new SimpleDateFormat("dd MMM yyyy hh:mm a", Locale.getDefault());
Date dt=dtfmt.parse(deptdt);
Run Code Online (Sandbox Code Playgroud)
在 Android 模拟器中工作正常,但在手机中出现此错误:
W/System.err: java.text.ParseException: Unparseable date: "24 Oct 2016 7:31 pm" (at offset 3) W/System.err: at java.text.DateFormat.parse(DateFormat.java:579)
有什么解决办法吗?
从https://api.spacexdata.com/v3/launches获取日期 该日期的格式为:2006-03-25T10:30:00+12:00。我想将其转换为“dd,mm,yyyy”,但总是收到错误:“java.time.format.DateTimeParseException:文本'2006-03-25T10:30:00 + 12:00'无法解析,未解析的文本发现于索引 10"
我的代码:
val formatter = DateTimeFormatter.ofPattern("dd, mm, yyyy", Locale.US)
val myDate = LocalDate.parse(launchDate, formatter)
var launchDateConverted: String= myDate.toString()
Run Code Online (Sandbox Code Playgroud)
我在字符串中获取数据,然后将其转换为日期进行格式化,然后将日期转换回字符串以在 UI 上显示。我使用了不同的方法,但找不到正确的方法。我当前的语言环境是“RU”。
android ×1
date ×1
datetime ×1
jackson ×1
java ×1
java-time ×1
json ×1
kotlin ×1
spring-mvc ×1
unparseable ×1