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.










share|improve this question




























    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.










    share|improve this question


























      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.










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 14:06









      Goncalo Peres

      1,1651314




      1,1651314










      asked Nov 7 at 5:02









      Bin

      11




      11





























          active

          oldest

          votes











          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',
          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
          });


          }
          });














          draft saved

          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python