【问题标题】:AngularJs formatting dateAngularJs 格式化日期
【发布时间】:2015-12-22 17:56:59
【问题描述】:

我不确定我的日期格式有什么问题。

我收到以下错误:

错误:[ngModel:nonassign] http://errors.angularjs.org/1.3.7/ngModel/nonassign?

profile-edit.html

<input id="birthday" type="date" class="form-control" ng-model="account.birthday | date" datepicker-options="dateOptions" close-text="Close" />

后端帐户实体:

@Entity
@Table(name = "account")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Account extends BaseEntity implements Serializable {
....
    @Column(name = "BIRTHDAY")
    private Date birthday;
}

在从后端获取帐户后,调试器中的 account.birthday 字段似乎以纯字符串形式保存毫秒数。

直接来自调试器:

活跃:真 生日:241912800000 城市:“埃森” 国家:“德国” 创建:1450289294000

我该如何解决这个问题?

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    我使用&lt;input type="date" data-ng-model="from_date"&gt; 作为 HTML 代码,然后在 Angular 中将其解析为日期

    var var_name = new Date($scope.from_date);
    

    【讨论】:

    • 诚实吗?对于我需要手动转换日期的每个字段? Angularjs api 声明它也可以处理毫秒(也可以作为纯字符串格式)。必须有一个简单的方法......
    猜你喜欢
    • 2016-01-27
    • 2014-04-20
    • 2017-12-10
    • 2015-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多