Java 将日期从引导数据采集器发送到带时区的Spring控制器

Java 将日期从引导数据采集器发送到带时区的Spring控制器,java,jquery,spring,jsp,bootstrap-datepicker,Java,Jquery,Spring,Jsp,Bootstrap Datepicker,1) 在jsp页面上: <input class="datepicker"/> -- 10.02.2017 2) Controller-Test.java @RequestMapping("test") public ModelAndView test(@PathVariable Date testDate){ // testDate = 09.02.2017 23:00:00 } 示例:我在数据采集器(引导)中选择2017年2月10日(№1) 并在控制器中获

1) 在jsp页面上:

<input class="datepicker"/>     -- 10.02.2017
2) Controller-Test.java

@RequestMapping("test")
public ModelAndView test(@PathVariable Date testDate){
      // testDate = 09.02.2017 23:00:00
}
示例:我在数据采集器(引导)中选择2017年2月10日(№1) 并在控制器中获取testDate(№2) 2017年2月9日23:00:00

我认为Spring或java.util.Date将testDate转换为服务器时区。但我可能错了


如何使用客户端时区从jsp上的bootstrap datepicker向Spring控制器发送日期值?我应该得到2017年2月10日的奖金

我已经找到了解决办法。 转换为Spring的日期类型值。 我曾写道:

public class DateConverter implements Converter<String, Date> {

@Override
public Date convert(String source) {
    SimpleDateFormat sf = new SimpleDateFormat("dd.MM.yyyy");
    if (!source.isEmpty()){
      try {
        return sf.parse(source);
      } catch (ParseException e) {
        LOGGER.error(e.getLocalizedMessage());
      }
    }
    return null;
}
当然可能会以不同的方式覆盖metod转换

public class DateConverter implements Converter<String, Date> {

@Override
public Date convert(String source) {
    SimpleDateFormat sf = new SimpleDateFormat("dd.MM.yyyy");
    if (!source.isEmpty()){
      try {
        return sf.parse(source);
      } catch (ParseException e) {
        LOGGER.error(e.getLocalizedMessage());
      }
    }
    return null;
}
@Override
public void addFormatters(FormatterRegistry registry) {
    registry.addConverter(new DateConverter());
}