我们需要格式化一个包含日期字符串的json响应属性(例如" 2017-01-29")。要格式化我们当前使用jquery UI函数的日期,如:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="235.0" prefWidth="203.0" styleClass="layout" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="uk.co.temp.QuestionController">
<children>
<BorderPane layoutX="-11.0" layoutY="35.0" prefHeight="235.0" prefWidth="203.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<bottom>
<Button fx:id="submitButton" mnemonicParsing="false" text="Submit" BorderPane.alignment="CENTER">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<BorderPane.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</BorderPane.margin>
</Button>
</bottom>
<top>
<Label fx:id="questionField" text="Insert Question Here" BorderPane.alignment="CENTER">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<BorderPane.margin>
<Insets left="10.0" right="10.0" top="10.0" />
</BorderPane.margin>
</Label>
</top>
<center>
<GridPane BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<RadioButton fx:id="toggle0" mnemonicParsing="false" text="Answer A">
<toggleGroup>
<ToggleGroup fx:id="answerGroup" />
</toggleGroup></RadioButton>
<RadioButton fx:id="toggle1" mnemonicParsing="false" text="Answer B" toggleGroup="$answerGroup" GridPane.rowIndex="1" />
<RadioButton fx:id="toggle2" mnemonicParsing="false" text="Answer C" toggleGroup="$answerGroup" GridPane.rowIndex="2" />
<RadioButton fx:id="toggle3" mnemonicParsing="false" text="Answer D" toggleGroup="$answerGroup" GridPane.rowIndex="3" />
<RadioButton fx:id="toggle4" mnemonicParsing="false" text="Answer E" toggleGroup="$answerGroup" GridPane.rowIndex="4" />
</children>
<padding>
<Insets top="10.0" />
</padding>
</GridPane>
</center>
</BorderPane>
</children>
</AnchorPane>
但是如果我们打印dayVar,它将显示为1月28日,17日,而不是预期的1月29日,17日。 什么是解决这个问题的最佳解决方案,以便它可以适应任何时区?
是使用Marionette框架构建的单页面应用程序。
答案 0 :(得分:1)
在实例化新的Date对象时,您将把时间留给解释。默认情况下,大多数环境会将此解释为00:00:00 ...但是,由于这是javascript,因此您可以使用本地计算机来解释此值。
我会将字符串中的00:00:00附加到Date()函数。为了实现预期的结果,或者甚至试图利用时间来查看它创建的输出类型(可能将其设置为1AM或22:00:00),这应该能够更深入地了解导致问题的原因,希望是解决方案。