How to create database timestamp input in HTML
So i have this payment history DB and one of its attribute is time in timestamp type (YYYY-MM-DD HH:MM:SS). I need to make form to add new payment history. My controller will automatically catch the payment history object and add it in DB. But since my time format in HTML (i pick datetime-local) did not match the time format in DB, i cannot proceed to add my new payment history.
Here's my error:
Field error in object 'paymentHistoryModel' on field 'time': rejected value
[2019-02-03T15:02]; codes
[typeMismatch.paymentHistoryModel.time,typeMismatch.time,
typeMismatch.java.sql.Timestamp,typeMismatch]; arguments
[org.springframework.context.support.DefaultMessageSourceResolvable: codes
[paymentHistoryModel.time,time]; arguments ; default message [time]];
default message [Failed to convert property value of type 'java.lang.String' to
required type 'java.sql.Timestamp' for property 'time'; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to convert
from type [java.lang.String] to type [@javax.validation.constraints.NotNull
@javax.persistence.Column java.sql.Timestamp] for value '2019-02-03T15:02';
nested exception is java.lang.IllegalArgumentException: Timestamp format must
be yyyy-mm-dd hh:mm:ss[.fffffffff]]
Is there any possible way to create HTML input with exact format like timestamp in my DB? Thankss!!
java html database input
add a comment |
So i have this payment history DB and one of its attribute is time in timestamp type (YYYY-MM-DD HH:MM:SS). I need to make form to add new payment history. My controller will automatically catch the payment history object and add it in DB. But since my time format in HTML (i pick datetime-local) did not match the time format in DB, i cannot proceed to add my new payment history.
Here's my error:
Field error in object 'paymentHistoryModel' on field 'time': rejected value
[2019-02-03T15:02]; codes
[typeMismatch.paymentHistoryModel.time,typeMismatch.time,
typeMismatch.java.sql.Timestamp,typeMismatch]; arguments
[org.springframework.context.support.DefaultMessageSourceResolvable: codes
[paymentHistoryModel.time,time]; arguments ; default message [time]];
default message [Failed to convert property value of type 'java.lang.String' to
required type 'java.sql.Timestamp' for property 'time'; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to convert
from type [java.lang.String] to type [@javax.validation.constraints.NotNull
@javax.persistence.Column java.sql.Timestamp] for value '2019-02-03T15:02';
nested exception is java.lang.IllegalArgumentException: Timestamp format must
be yyyy-mm-dd hh:mm:ss[.fffffffff]]
Is there any possible way to create HTML input with exact format like timestamp in my DB? Thankss!!
java html database input
You'd need to parse the string yourself, i.e. in your code. Without any more information, especially some code (keep in mind that it should be short, ideally a Minimal, Complete, and Verifiable example) it's hard to tell more.
– Thomas
Nov 21 '18 at 12:47
Welcome to SO! According to the error message, your input timestamp was '2019-02-03T15:02' which of course does not match your format 'YYYY-MM-DD HH:MM:SS'.
– xoX Zeus Xox
Nov 21 '18 at 12:48
add a comment |
So i have this payment history DB and one of its attribute is time in timestamp type (YYYY-MM-DD HH:MM:SS). I need to make form to add new payment history. My controller will automatically catch the payment history object and add it in DB. But since my time format in HTML (i pick datetime-local) did not match the time format in DB, i cannot proceed to add my new payment history.
Here's my error:
Field error in object 'paymentHistoryModel' on field 'time': rejected value
[2019-02-03T15:02]; codes
[typeMismatch.paymentHistoryModel.time,typeMismatch.time,
typeMismatch.java.sql.Timestamp,typeMismatch]; arguments
[org.springframework.context.support.DefaultMessageSourceResolvable: codes
[paymentHistoryModel.time,time]; arguments ; default message [time]];
default message [Failed to convert property value of type 'java.lang.String' to
required type 'java.sql.Timestamp' for property 'time'; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to convert
from type [java.lang.String] to type [@javax.validation.constraints.NotNull
@javax.persistence.Column java.sql.Timestamp] for value '2019-02-03T15:02';
nested exception is java.lang.IllegalArgumentException: Timestamp format must
be yyyy-mm-dd hh:mm:ss[.fffffffff]]
Is there any possible way to create HTML input with exact format like timestamp in my DB? Thankss!!
java html database input
So i have this payment history DB and one of its attribute is time in timestamp type (YYYY-MM-DD HH:MM:SS). I need to make form to add new payment history. My controller will automatically catch the payment history object and add it in DB. But since my time format in HTML (i pick datetime-local) did not match the time format in DB, i cannot proceed to add my new payment history.
Here's my error:
Field error in object 'paymentHistoryModel' on field 'time': rejected value
[2019-02-03T15:02]; codes
[typeMismatch.paymentHistoryModel.time,typeMismatch.time,
typeMismatch.java.sql.Timestamp,typeMismatch]; arguments
[org.springframework.context.support.DefaultMessageSourceResolvable: codes
[paymentHistoryModel.time,time]; arguments ; default message [time]];
default message [Failed to convert property value of type 'java.lang.String' to
required type 'java.sql.Timestamp' for property 'time'; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to convert
from type [java.lang.String] to type [@javax.validation.constraints.NotNull
@javax.persistence.Column java.sql.Timestamp] for value '2019-02-03T15:02';
nested exception is java.lang.IllegalArgumentException: Timestamp format must
be yyyy-mm-dd hh:mm:ss[.fffffffff]]
Is there any possible way to create HTML input with exact format like timestamp in my DB? Thankss!!
java html database input
java html database input
edited Nov 21 '18 at 12:48
Roshana Pitigala
4,81162449
4,81162449
asked Nov 21 '18 at 12:44
mollymaxmollymax
6
6
You'd need to parse the string yourself, i.e. in your code. Without any more information, especially some code (keep in mind that it should be short, ideally a Minimal, Complete, and Verifiable example) it's hard to tell more.
– Thomas
Nov 21 '18 at 12:47
Welcome to SO! According to the error message, your input timestamp was '2019-02-03T15:02' which of course does not match your format 'YYYY-MM-DD HH:MM:SS'.
– xoX Zeus Xox
Nov 21 '18 at 12:48
add a comment |
You'd need to parse the string yourself, i.e. in your code. Without any more information, especially some code (keep in mind that it should be short, ideally a Minimal, Complete, and Verifiable example) it's hard to tell more.
– Thomas
Nov 21 '18 at 12:47
Welcome to SO! According to the error message, your input timestamp was '2019-02-03T15:02' which of course does not match your format 'YYYY-MM-DD HH:MM:SS'.
– xoX Zeus Xox
Nov 21 '18 at 12:48
You'd need to parse the string yourself, i.e. in your code. Without any more information, especially some code (keep in mind that it should be short, ideally a Minimal, Complete, and Verifiable example) it's hard to tell more.
– Thomas
Nov 21 '18 at 12:47
You'd need to parse the string yourself, i.e. in your code. Without any more information, especially some code (keep in mind that it should be short, ideally a Minimal, Complete, and Verifiable example) it's hard to tell more.
– Thomas
Nov 21 '18 at 12:47
Welcome to SO! According to the error message, your input timestamp was '2019-02-03T15:02' which of course does not match your format 'YYYY-MM-DD HH:MM:SS'.
– xoX Zeus Xox
Nov 21 '18 at 12:48
Welcome to SO! According to the error message, your input timestamp was '2019-02-03T15:02' which of course does not match your format 'YYYY-MM-DD HH:MM:SS'.
– xoX Zeus Xox
Nov 21 '18 at 12:48
add a comment |
1 Answer
1
active
oldest
votes
You can use java.text.SimpleDateFormat to change the date time format.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"),
sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date parse = sdf.parse("2019-02-03T15:02".replace("T", " "));
String dateTime = sdf2.format(parse);
System.out.println(dateTime);
OUTPUT
2019-02-03 15:02:00
Read more about the Date and Time Patterns.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412326%2fhow-to-create-database-timestamp-input-in-html%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use java.text.SimpleDateFormat to change the date time format.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"),
sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date parse = sdf.parse("2019-02-03T15:02".replace("T", " "));
String dateTime = sdf2.format(parse);
System.out.println(dateTime);
OUTPUT
2019-02-03 15:02:00
Read more about the Date and Time Patterns.
add a comment |
You can use java.text.SimpleDateFormat to change the date time format.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"),
sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date parse = sdf.parse("2019-02-03T15:02".replace("T", " "));
String dateTime = sdf2.format(parse);
System.out.println(dateTime);
OUTPUT
2019-02-03 15:02:00
Read more about the Date and Time Patterns.
add a comment |
You can use java.text.SimpleDateFormat to change the date time format.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"),
sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date parse = sdf.parse("2019-02-03T15:02".replace("T", " "));
String dateTime = sdf2.format(parse);
System.out.println(dateTime);
OUTPUT
2019-02-03 15:02:00
Read more about the Date and Time Patterns.
You can use java.text.SimpleDateFormat to change the date time format.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"),
sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date parse = sdf.parse("2019-02-03T15:02".replace("T", " "));
String dateTime = sdf2.format(parse);
System.out.println(dateTime);
OUTPUT
2019-02-03 15:02:00
Read more about the Date and Time Patterns.
answered Nov 21 '18 at 12:55
Roshana PitigalaRoshana Pitigala
4,81162449
4,81162449
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412326%2fhow-to-create-database-timestamp-input-in-html%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You'd need to parse the string yourself, i.e. in your code. Without any more information, especially some code (keep in mind that it should be short, ideally a Minimal, Complete, and Verifiable example) it's hard to tell more.
– Thomas
Nov 21 '18 at 12:47
Welcome to SO! According to the error message, your input timestamp was '2019-02-03T15:02' which of course does not match your format 'YYYY-MM-DD HH:MM:SS'.
– xoX Zeus Xox
Nov 21 '18 at 12:48