Angular 7 Spring boot 2 MongoDB timezone offset problem
up vote
0
down vote
favorite
Angular 7 + Spring boot 2 + MongoDB
Date input timezone offset problem:
Pick a date at Angular HTML, through spring boot to MongoDB. When pulling out the date from MongoDB to HTML, it is not the expected result.
Please see the process:
1,
customer.ts :
export class Customer {
id: String;
lastname: string;
firstname: string;
middleinitial: string;
dob: Date;
gender: string;
handdominance: string;
active: boolean;
}
2,
create-customer.component.html
<input type="date" class="form-control" id="dob" required [(ngModel)]="customer.dob" name="dob">
-- pick a date: 11/06/2018 (local time zone is MST)
same html page:
<label>DOB: </label> {{customer.dob | date: 'medium' :'MST'}}
--display result : DOB: Nov,6,2018, 12:00:00 AM (it is correct.)
3,
After submitting to create-customer.component.ts
save() {
console.log(this.customer);
this.customerService.createCustomer(this.customer)
.subscribe(
data => {
console.log(data);
this._customer = data as Customer;
},
error => console.log(error));
this.customer = new Customer();
}
--1st log is: Customer {dob: "2018-11-06"} (no timezone info)
there is no timezone info in the 1st log.
--2nd log is: {id: "5be24991cb4b0123bc9c1a26", lastname: null, firstname: null, middleinitial: null, dob: "2018-11-06T00:00:00.000+0000",?¡}
2nd log's result is returned from DB. it's UTC time. Expect is "2018-11-06T07:00:00.000+0000"
4,
CustomerController.java
System.out.println("Create Customer..." + customer.getDob());
console display result: Create Customer...Mon Nov 05 17:00:00 MST 2018 (it's local time(MST), but it is not expect result)
5,
MongoDB result:
{
"_id" : ObjectId("5be25aa7cb4b0123bc9c1a29"),
"dob" : ISODate("2018-11-06T00:00:00Z"),
"active" : false,
"_class" : "com.example.demo.model.Customer"
}
How can I do to get the right result?
Thanks.
spring angular mongodb spring-boot angular7
add a comment |
up vote
0
down vote
favorite
Angular 7 + Spring boot 2 + MongoDB
Date input timezone offset problem:
Pick a date at Angular HTML, through spring boot to MongoDB. When pulling out the date from MongoDB to HTML, it is not the expected result.
Please see the process:
1,
customer.ts :
export class Customer {
id: String;
lastname: string;
firstname: string;
middleinitial: string;
dob: Date;
gender: string;
handdominance: string;
active: boolean;
}
2,
create-customer.component.html
<input type="date" class="form-control" id="dob" required [(ngModel)]="customer.dob" name="dob">
-- pick a date: 11/06/2018 (local time zone is MST)
same html page:
<label>DOB: </label> {{customer.dob | date: 'medium' :'MST'}}
--display result : DOB: Nov,6,2018, 12:00:00 AM (it is correct.)
3,
After submitting to create-customer.component.ts
save() {
console.log(this.customer);
this.customerService.createCustomer(this.customer)
.subscribe(
data => {
console.log(data);
this._customer = data as Customer;
},
error => console.log(error));
this.customer = new Customer();
}
--1st log is: Customer {dob: "2018-11-06"} (no timezone info)
there is no timezone info in the 1st log.
--2nd log is: {id: "5be24991cb4b0123bc9c1a26", lastname: null, firstname: null, middleinitial: null, dob: "2018-11-06T00:00:00.000+0000",?¡}
2nd log's result is returned from DB. it's UTC time. Expect is "2018-11-06T07:00:00.000+0000"
4,
CustomerController.java
System.out.println("Create Customer..." + customer.getDob());
console display result: Create Customer...Mon Nov 05 17:00:00 MST 2018 (it's local time(MST), but it is not expect result)
5,
MongoDB result:
{
"_id" : ObjectId("5be25aa7cb4b0123bc9c1a29"),
"dob" : ISODate("2018-11-06T00:00:00Z"),
"active" : false,
"_class" : "com.example.demo.model.Customer"
}
How can I do to get the right result?
Thanks.
spring angular mongodb spring-boot angular7
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Angular 7 + Spring boot 2 + MongoDB
Date input timezone offset problem:
Pick a date at Angular HTML, through spring boot to MongoDB. When pulling out the date from MongoDB to HTML, it is not the expected result.
Please see the process:
1,
customer.ts :
export class Customer {
id: String;
lastname: string;
firstname: string;
middleinitial: string;
dob: Date;
gender: string;
handdominance: string;
active: boolean;
}
2,
create-customer.component.html
<input type="date" class="form-control" id="dob" required [(ngModel)]="customer.dob" name="dob">
-- pick a date: 11/06/2018 (local time zone is MST)
same html page:
<label>DOB: </label> {{customer.dob | date: 'medium' :'MST'}}
--display result : DOB: Nov,6,2018, 12:00:00 AM (it is correct.)
3,
After submitting to create-customer.component.ts
save() {
console.log(this.customer);
this.customerService.createCustomer(this.customer)
.subscribe(
data => {
console.log(data);
this._customer = data as Customer;
},
error => console.log(error));
this.customer = new Customer();
}
--1st log is: Customer {dob: "2018-11-06"} (no timezone info)
there is no timezone info in the 1st log.
--2nd log is: {id: "5be24991cb4b0123bc9c1a26", lastname: null, firstname: null, middleinitial: null, dob: "2018-11-06T00:00:00.000+0000",?¡}
2nd log's result is returned from DB. it's UTC time. Expect is "2018-11-06T07:00:00.000+0000"
4,
CustomerController.java
System.out.println("Create Customer..." + customer.getDob());
console display result: Create Customer...Mon Nov 05 17:00:00 MST 2018 (it's local time(MST), but it is not expect result)
5,
MongoDB result:
{
"_id" : ObjectId("5be25aa7cb4b0123bc9c1a29"),
"dob" : ISODate("2018-11-06T00:00:00Z"),
"active" : false,
"_class" : "com.example.demo.model.Customer"
}
How can I do to get the right result?
Thanks.
spring angular mongodb spring-boot angular7
Angular 7 + Spring boot 2 + MongoDB
Date input timezone offset problem:
Pick a date at Angular HTML, through spring boot to MongoDB. When pulling out the date from MongoDB to HTML, it is not the expected result.
Please see the process:
1,
customer.ts :
export class Customer {
id: String;
lastname: string;
firstname: string;
middleinitial: string;
dob: Date;
gender: string;
handdominance: string;
active: boolean;
}
2,
create-customer.component.html
<input type="date" class="form-control" id="dob" required [(ngModel)]="customer.dob" name="dob">
-- pick a date: 11/06/2018 (local time zone is MST)
same html page:
<label>DOB: </label> {{customer.dob | date: 'medium' :'MST'}}
--display result : DOB: Nov,6,2018, 12:00:00 AM (it is correct.)
3,
After submitting to create-customer.component.ts
save() {
console.log(this.customer);
this.customerService.createCustomer(this.customer)
.subscribe(
data => {
console.log(data);
this._customer = data as Customer;
},
error => console.log(error));
this.customer = new Customer();
}
--1st log is: Customer {dob: "2018-11-06"} (no timezone info)
there is no timezone info in the 1st log.
--2nd log is: {id: "5be24991cb4b0123bc9c1a26", lastname: null, firstname: null, middleinitial: null, dob: "2018-11-06T00:00:00.000+0000",?¡}
2nd log's result is returned from DB. it's UTC time. Expect is "2018-11-06T07:00:00.000+0000"
4,
CustomerController.java
System.out.println("Create Customer..." + customer.getDob());
console display result: Create Customer...Mon Nov 05 17:00:00 MST 2018 (it's local time(MST), but it is not expect result)
5,
MongoDB result:
{
"_id" : ObjectId("5be25aa7cb4b0123bc9c1a29"),
"dob" : ISODate("2018-11-06T00:00:00Z"),
"active" : false,
"_class" : "com.example.demo.model.Customer"
}
How can I do to get the right result?
Thanks.
spring angular mongodb spring-boot angular7
spring angular mongodb spring-boot angular7
edited Nov 11 at 14:06
Goncalo Peres
1,1651314
1,1651314
asked Nov 7 at 5:02
Bin
11
11
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53183818%2fangular-7-spring-boot-2-mongodb-timezone-offset-problem%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