English 中文(简体)
• 防止日期改为当地时间区
原标题:How to prevent date conversion to local time zone with DayJS

页: 1

问题在于我通过正义与平等国际日把这个问题混为一谈。

dayjs (someDate).format ( h:mm A )

我回到了我的地方时区,当时我需要像我一样。

无论怎样才能将时间转换到DdayJS的地方时间区?

最佳回答

Yes!

你可以通过在原时区通过,作为日常建筑师的另一种理由,将白天区改成当地时间区,这是不可行的。

<>>Example:

const someDate = "2023-02-13T09:00:00.000-05:00";
const originalTimezone = someDate.slice(-6);
const formattedDate = dayjs(someDate).utcOffset(originalTimezone).format( h:mm A );

utcOffset() 方法允许你在具体日期的几分钟内从UTC中扣除。 <代码>原始时间段不变,用于从显示的原始日期起抽取<代码>>tDate,并将之通过<编码>utcOffset()。 这将确保原定日期留在原时区。

问题回答

您可使用utc plugin。

import dayjs from "dayjs";
import utc from  dayjs/plugin/utc ;

dayjs.extend(utc)


const dateTime = "2023-02-13T09:00:00.000-05:00";
const value = dayjs.utc(dateTime).format( h:mm A );

console.log(value);

我认为,最简单的办法是实际提供“投入”和“产出”TZ:

const twoThirtyThreeNoMatterWhat = dayjs( 02-05-21 02:33 PM GMT ).tz( GMT ).format(FMT),

这基本上与@Filip Huhta相同,但并不需要打平抵消——尽管你当然可以硬编码,以便他的回答变成了。

const formattedDate = dayjs(someDate).utcOffset( -5:00 ).format( h:mm A );

这当然是罚款,尽管它具有的特性比地雷更小。

The important thing, though, is that because they are both the same, they don t matter as long as they are both the same.

当然,只有你真正掌握投入,才能做到这一点。 如果说,你把<条码>日js重新命名,并附上你所写的某些案文,那么你就可以把这一功能称作你所希望的一切。 我这样说,这就是:通常是

我还认为,如果你真的关心时间区,那么我的战略是有效的。 由于你所希望的格式是<代码>h:mm A,我想象你会说什么是9:00 AM,这符合大家的关心。 (我还声称,this通常是这种情况?)





相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签