How to convert datetime into a number?
71 次查看(过去 30 天)
显示 更早的评论
I have a table whose first column is a timestamp in the format 08-Jan-2016 05:40:00. How do I convert it into numbers?
Wanted output: 20160108054000.
I know the function yyyymmdd(X) is useful but I also need the time to be added.
Thanks!
回答(2 个)
KSSV
2022-4-3
dt = datestr(now,'yyyymmddHHMMSS')
5 个评论
Siddharth Bhutiya
2022-4-5
Avoid using older legacy functions like datestr and datenum. Use the more modern types like datetime to work with timestamped data.
@Lu Da Silva Could you share a code example to demonstrate what you are seeing. This way people can run that on their MATLAB and suggest possible solutions instead of trying to guess what the problem could be.
Boyd Tolton
2024-8-6,17:41
Although datetime does provide more precision than datenum (and requires more memory), this precision is not needed by most applications. Also, you will note that the dir command outputs the datenum for files.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!