What is the best data type to accurately store dates and times for a schedule in Spring Boot

huangapple go评论52阅读模式
英文:

What is the best data type to accurately store dates and times for a schedule in Spring Boot

问题

Sure, here are the translated parts:

我正在创建一个应用程序,允许人们使用Spring Boot安排医生的预约。应用程序的一部分包含一个表格,用于存储特定医生的可用时间和日期。

表格的属性包括:

  • Id(标识)
  • 医生 Id
  • 时间
  • 日期
  • 类型
  • 评论

我的问题是,在Spring Boot中,用于“时间”和“日期”属性的最佳数据类型是什么,以便能够准确地表示和存储这些数据?

我在考虑是否使用列表的形式,但我不知道它是否是最佳选项。

英文:

I am creating an application that allows for people to schedule an appointment for a doctor using spring boot. Part of the application contains a table to store the available times and dates for a particular doctor.

The attributes for the table are:

  • Id
  • Doctor Id
  • Time
  • Date
  • Type
  • Comment

My question is what data types would be best to use for the "time" and "date" attribute in Spring Boot that would best allow me to accurately represent and store this data?

I was think a form of list, but I don't know how if it would be the best option.

答案1

得分: 2

如果你想将日期和时间存储在不同的字段中,请使用 LocalDateLocalTime 类。如果你想将它们保留在一个字段中,你可以使用 LocalDateTime,如果你想要一个对确切时刻的引用,你将需要一个偏移引用,然后你需要使用 OffsetDateTimeZonedDateTime。总的来说,请查阅 java.time 包。

英文:

If you want to store Date and time in separate fields than use LocalDate and LocalTime classes. If you want to keep them in one field you can use LocalDateTime or if you want to have a reference to exact moment you will have to have offset reference, and than you will need to use OffsetDateTime or ZonedDateTime. In general, read up on package java.time.

答案2

得分: 0

Michael提供的答案告诉您在Spring应用中应该使用哪种数据类型,您可以创建一个LocalDateTime值的列表来存储所有可用的时间,或者您可以在前端实现这一点,因为从开放时间到关闭时间拥有一个小时数组会更容易,只显示医生可用的小时。毕竟,在前端实现会更容易,假设您实现了一个前端。

英文:

The answer that Michael gave tells you what data type should you use in your Spring app and you can either create a list of LocalDateTime values to store all the available times or you can implement that rather in your front-end because it would be a lot easier to have an array of hours from your open time until your closing time and retrieving the existing appointments only showing the hours that the doctor is available. After all the implementation would be a lot easier in the front-end assuming you implement one.

huangapple
  • 本文由 发表于 2023年4月19日 19:05:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76053759.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定