shifting time in timetable
15 次查看(过去 30 天)
显示 更早的评论
i want to shift this timetable for 1 day it means i want this, start from 03-jan-2018 regardless of hours
0 个评论
采纳的回答
dpb
2018-10-25
Not sure what the "want" really means--the present time just a day later for each observation or what, precisely?
On the presumption that's the correct guess, then
TT.Time=TT.Time+1;
2 个评论
Peter Perkins
2018-10-31
This works, but for two reasons I would recommend adding caldays(1) rather than just 1.
1) For backwards compatibility reasons, 1 is interpreted as a datenum, i.e. days(1). But that's perhaps not obvious to someone reading the code at some later time.
2) Getting in the habit of using caldays for calendar arithmetic is a good idea, because someday, you're going to be working with zoned datetimes, and adding a day to a Sat that happens to be the day before a DST shift. days(1) means "exactly 24 hours", which probably isn't what you'd want, while caldays(1) means "one calendar day", which probably is.
>> dt = datetime(2018,11,3,14,0,0,'TimeZone','America/New_York')
dt =
datetime
03-Nov-2018 14:00:00
>> dt + days(1)
ans =
datetime
04-Nov-2018 13:00:00
>> dt + caldays(1)
ans =
datetime
04-Nov-2018 14:00:00
days is mostly intended as a shorthand for "24 hours" when you are working with "exact times" and durations.
dpb
2018-10-31
Good points, Peter.
I didn't have a klew as to what the OP was asking so was hoping for a response as to what the desire really was so I just took the shortcut to try to begin the conversation. Hadn't realized OP even came back until saw your comment just now...
更多回答(1 个)
jonas
2018-10-25
编辑:jonas
2018-10-25
Simply shifting the time without affecting the data
TT.Time = dateshift(TT.Time,'start','day')
Changing the format (hiding the time of day)
TT.Time.Format = 'dd-MMM-yyyy'
Calculating a daily average
TT2 = retime(TT,'daily','mean')
These are the answers to three possible interpretations of your question. Perhaps you could describe your problem a bit better next time.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!