JPA日期不显示小时/分钟/秒

时间:2016-02-03 22:53:34

标签: java date jpa

我的课程参数为Date。

private class LoginParameters {
    public string Name { get; set; }
    public string Password { get; set; }
    // Any other properties needed
}

// Make this a property of your form.
BackgroundWorker LoginWorker { get; set; }

// Somewhere in your UI code after the user clicks the "login button"
LoginWorker = new BackgroundWorker();
LoginWorker.WorkerReportsProgress = true;
LoginWorker.WorkerSupportsCancellation = true; // Can set to false if you don't allow the operation to be cancelled.
LoginWorker.DoWorker += DoLogin;
LoginWorker.ProgressChanged += ReportProgress;
LoginWorker.RunWorkerCompleted += LoginFinished;

LoginParameters login = new LoginParameters {
    // Code to initialize everything here
};

LoginWorker.RunWorkerAsync(login);

// Put this in the click event handler for the Cancel button, if you have one
if ( LoginWorker != null )
    LoginWorker.CancelAsync();

private void DoLogin(object sender, DoWorkEventArgs e) {
    BackgroundWorker worker = (BackgroundWorker) sender; 
    LoginParameters login = (LoginParameters) e.Argument;

    // Your logic to process the login goes here. It should periodically do the following to check to see if the user clicked the cancel button:
    if ( worker.CancellationPending ) {
        e.Cancel = true;
        return;
    }

    // When you want to update the UI, do this:
    worker.ReportProgress( percentComplete, objectWithOtherDataToWriteToTheUI );

    // When you're done, just return.
}

private void ReportProgress(object sender, ProgressChangedEventArgs e) {
    // Your code to extract the data you need to update the display from the arguments & to then update the display goes here.  Remember, this runs on the UI thread
    }

private void LoginFinished( object sender, RunWorkerCompletedEventArgs e ) {
    if (e.Cancelled == true)
        // Your code to inform the user of the cancellation here
    else if (e.Error != null)
        // All unhadgled exceptions throws by the DoWork event handler end up here
        // Your code to inform the user of the error here
    else {
        // Your code to inform the user of the success goes here.
        // Remember, this runs on the UI thread.

        // I recommend you set the form BackgroundWorker property to null after its finished, as you can't reuse it after its finished. 
        LoginWorker = null;
    }
}

当我将对象保存到db。

我的约会不完整。 db只有@Temporal(javax.persistence.TemporalType.DATE) @Column(name = DomainConstant.DOMAIN_LOGIN_LOG_DATE) private Date date; ,但为什么呢?如何将完整日期存储在2016-02-03等格式中?

当然,我可以使用字符串,但如何使用日期?

1 个答案:

答案 0 :(得分:2)

以下是您要记录时间和日期的内容

@Temporal(javax.persistence.TemporalType.TIMESTAMP)
    @Column(name = DomainConstant.DOMAIN_LOGIN_LOG_DATE)
    private Date date;
相关问题