0

i am creating a project in angular and spring boot.

upon a certain event i send a date type object (called start time) from angular to spring boot which is written is in java i am facing 2 problems:

  1. when i send the startTime from angular it is sent in indian standard time. but when i receive the start time in the back-end it is stored in utc format so there is -5.30 time difference

  2. when i bring back the startTime at time of login (from back-end) i can display it in form of console.log(startTime) but when i do startTime.getHours(),startTime.getMinutes() etc. it shows an error that the getHours() is not a function of startTime

guys can anyone help me with both of the problem..

here is my scheduleData.ts which has startTime

export class scheduleData {
    public StartTime: Date;
    public EndTime: Date;
}

now here is my java code

public class ScheduleDataModel {

    public LocalDateTime StartTime;
    public LocalDateTime EndTime;

}
7
  • 1
    Use ZonedDateTime? Commented May 16, 2020 at 19:11
  • @GetMeARemoteJob i tried to it but not able to implement it..and what about the second problem Commented May 16, 2020 at 19:14
  • 1
    when you get it back from server, you need to parse it again to a date object. Commented May 16, 2020 at 19:15
  • so in between do i have to send it in a string form? Commented May 16, 2020 at 19:16
  • 1
    You should follow the Java Naming Conventions: variabele names and method names should be written in camelCase. Commented May 16, 2020 at 19:57

1 Answer 1

1

1.) If you send or receive a date, the informaton is sent as a date string. In most cases it's a part of a json. You must always send (or get) a timezone.

2.) You get a string. You have to parse it:

const d = new Date(yourDateString);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.