how can I convert EST time to GMt time?

조회 수: 8 (최근 30일)
Riyadh Muttaleb
Riyadh Muttaleb 2018년 2월 26일
댓글: Meade 2018년 3월 1일
I have series of datevec (about 1000) in EST time zone that I would like to convert them to GMT, any help,
Thanks in advance,
Riyadh

답변 (2개)

Meade
Meade 2018년 2월 26일
Try using the 'TimeZone' property in the datetime function to re-interpret the input time in a new time zone.
Best,
  댓글 수: 1
Riyadh Muttaleb
Riyadh Muttaleb 2018년 2월 26일
Thank you for your response, I have matrix of time (series) not one value

댓글을 달려면 로그인하십시오.


Peter Perkins
Peter Perkins 2018년 2월 28일
Unless you are using a version of MATLAB prior to R2014b, you probably should not be using datevecs. Convert them to datetimes.
>> dv = [2018,2,28,9,16,34; 2018,2,28,9,16,49;2018,2,28,9,17,04]
dv =
2018 2 28 9 16 34
2018 2 28 9 16 49
2018 2 28 9 17 4
>> dt = datetime(dv,'TimeZone','America/New_York','Format','dd-MMM-uuuu HH:mm:ss z')
dt =
3×1 datetime array
28-Feb-2018 09:16:34 EST
28-Feb-2018 09:16:49 EST
28-Feb-2018 09:17:04 EST
>> dt.TimeZone = 'UTC'
dt =
3×1 datetime array
28-Feb-2018 14:16:34 UTC
28-Feb-2018 14:16:49 UTC
28-Feb-2018 14:17:04 UTC
  댓글 수: 3
Peter Perkins
Peter Perkins 2018년 3월 1일
datetime does recognize some common formats. One of the problems with datenum/datestr/datevec was that they guess too much and sometimes get it wrong, silently.
Most common example is 01/02/2018. Because that's so common, datetime has some logic for that case based on your locale are and whether you also have, for example, 01/15/2018. So for me, in the US, it guesses month/day:
>> datetime('01/02/2018')
Warning: Successfully converted the text to datetime using the format 'MM/dd/uuuu', but the format is ambiguous and
could also be 'dd/MM/uuuu'. To create datetimes from text with a specific format call:
datetime(textinput,'InputFormat',infmt)
> In guessFormat (line 66)
In datetime (line 631)
ans =
datetime
02-Jan-2018
But this case is unambiguous:
>> datetime({'01/02/2018' '01/15/2018'})
ans =
1×2 datetime array
02-Jan-2018 15-Jan-2018
Meade
Meade 2018년 3월 1일
Thanks for the extra detail, I'll keep datetime in mind as I revamp processes.
I work with lots of data downstream of a workflow that doesn't adhere rigorously to a single format (e.g. ISO-8601) and in turn, I'll (cautiously) take all the help I can get.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by