在使用Java8之前,我使用了Joda的DateTime类来包含时区信息,并且可以很容易地在DateTime和Timestamp之间进行转换。
一旦迁移到Java8,我应该替换哪个类?OffsetDateTime还是ZonedDateTime
此外,我尝试使用OffsetDateTime,但它似乎不能从sql Timestamp构造回OffsetDateTime。
对于Joda DateTime和Timestamp转换器,代码如下:
val joda = DateTime.now()
val sqlJoda = new Timestamp(joda.getMillis)
val jodaBac
我需要将当前的日期和时间导入MySQL数据库字段,该字段的格式为。从样本数据来看,MySQL TimeStamp数据类型的格式似乎是“yyyy:mm:ss”。我在我的spring应用程序中使用格式。如何以基础MySQL TimeStamp格式化字段将接受的格式获取当前日期时间?
下面是我的当前代码,它不会编译,因为eclipse说.parseDateTime()需要字符串参数,而不是DateTime参数:
public void setCreated(){
DateTime now = new org.joda.time.DateTime();
DateTimeFormatte
在Android设备(7.0)上,有这样的崩溃:
Fatal Exception: org.joda.time.IllegalInstantException: Illegal instant due to time zone offset transition (daylight savings time 'gap'): 1977-05-01T00:00:00.000 (Africa/Casablanca)
at org.joda.time.chrono.ZonedChronology.localToUTC(ZonedChronology.java:157)
我有以下几点:
val startWithTZ = new DateTime("2016-10-01T00:00:00", DateTimeZone.UTC)
val endWithTZ = new DateTime("2016-10-01T11:00:00", DateTimeZone.UTC)
val intervalWithTZ = new Interval(startWithTZ, endWithTZ)
val startWithoutTZ = new DateTime("2016-10-01T00:00:00")
val endWit
我试图理解AT TIME ZONE的行为,在这方面我发现Server和PostgreSQL之间有一些奇怪的行为差异。
为了演示起见,我产生了两个查询,一个用于Server,另一个用于PostgreSQL。
Server查询:
SELECT
[LocalTime],
[LocalTime] AT TIME ZONE 'W. Europe Standard Time' AS [LocalTimeWithOffset],
([LocalTime] AT TIME ZONE 'W. Europe Standard Time') AT TIME ZONE
正如您在下面看到的,在序列化和非序列化之后,您得到了应该是不同的DateTime实例:
scala> import org.joda.time.DateTime
import org.joda.time.DateTime
scala> val a = new DateTime()
a: org.joda.time.DateTime = 2014-01-08T19:00:08.883+02:00
scala> val b = DateTime.parse(a.toString())
b: org.joda.time.DateTime = 2014-01-08T19:00:0
我的应用程序接收字符串格式的时间戳,我们在SimpleDateFormat类中使用parse()方法将该字符串转换为Timestamp对象。我的应用程序是在America/New_York时区运行的,因此我们面临着3月9日凌晨2点到2点59分之间的时间戳的夏令时问题我们通过修改默认时区属性以确保将所有夏令时字段重置为零,修复了此问题。但是,当我们在夏令时更改后(3月22日)使用java.util.Date类创建current timestamp对象时,它显示为比实际的当前时间戳少了1小时。这是因为更改了默认时区的属性。
public class DateTest {
static Ti
这段代码工作正常,但我想使用Joda-Time
public static Date dateFromUTC(Date date){
return new Date(date.getTime() + Calendar.getInstance().getTimeZone().getOffset(date.getTime()));
}
我试过了,但它不工作-这是什么问题?
public static Date dateFromUTC(Date date){
return new DateTime(date).withZone(DateTimeZone.get
我在PostgreSQL中有一个包含此特定日期列的表,我需要使用slick2.0根据一个特定Id检索所有记录,我使用Joda来管理日期
MyTable
(
IdTable Int NOT NULL,
Name varchar(64),
Created_Date timestamp with time zone DEFAULT now()
)
然后我尝试以这种方式在Slick中映射它:
val Created_Date: Column[OptionDateTime] = columnOptionDateTime
一旦我在表中添加了Created_Date列,检索记录的方
我有一个存储了joda time DateTime对象的数据源。我需要将它们转换为java ZonedDateTime对象,保持原来的时区。
仅保留偏移量是不够的,因为一些DateTime对象代表每天重复的任务,而且这些任务必须在特定时间发生在特定时区的每个日期。因此,它们必须遵循指定的TimeZone转换,例如夏季和冬季。我无法告诉DateTime对象的最终使用情况,因此我需要保存所有对象的时区信息,以确保安全。
如何从org.joda.time.DateTime转换为java.time.ZonedDateTime?
Will all
ord.joda.time.DateTimeZone.
我试图在查询开始时声明一个datetime变量,该变量保存查询的运行时。我正在拉UTC的时间,但我需要东部时间。
我尝试了以下代码:
DECLARE @RunDate as datetimeoffset
SET @RunDate = CURRENT_TIMESTAMP at time zone 'Eastern Standard Time'
DECLARE @RunDateEST as datetime
SET @RunDateEST = CONVERT(DATETIME, SWITCHOFFSET(@RunDate, DATEPART(tz, SYSDATETI