how get date fromthe long number?

Hi,
The following number represent date
1246573330
How get a date from it ? where I tried datenum,datestr, and datevec, but does not working
Thanks

2 Comments

Which date format is this number representing? The Unix epoch?
Unix time stamp

Sign in to comment.

 Accepted Answer

D = 1246573330;
DT1 = datetime(D, 'ConvertFrom','datenum')
DT1 = datetime
3413001 CE
DT2 = datetime(D, 'ConvertFrom','excel')
DT2 = datetime
3414901 CE
DT3 = datetime(D, 'ConvertFrom','posixtime')
DT3 = datetime
02-Jul-2009 22:22:10
DT4 = datetime(D, 'ConvertFrom','juliandate')
DT4 = datetime
3408289 CE
.

10 Comments

This is work
DT3 = datetime(D, 'ConvertFrom','posixtime')
But I do not know, what the othors represent
As always, my pleasure!
But I do not know, what the othors represent
What are the ‘others’?
There's a table on the documentation page for the datetime function (in the section that talks about the dateType input argument) that describes how D is interpreted for each of the different dateTypes.
The values for datenum, excel, and juliandate are so large because each of those interpret D as a number of days and 1.25 billion days is a long time. The posixtime value interprets D as a number of seconds and 1.25 billion seconds isn't quite as long a time.
format longg
years(days(1.25e9)) % 3 million-ish
ans =
3422383.75873563
years(seconds(1.25e9)) % 40-ish
ans =
39.6109231335143
I means those
DT1 = datetime(D, 'ConvertFrom','datenum')
DT2 = datetime(D, 'ConvertFrom','excel')
DT4 = datetime(D, 'ConvertFrom','juliandate')
But steven clarified it
Hello
Now i need to convert 06-Aug-2005 13:22:50 into number
what is the function should use?
THANKS
I googled 'datetime matlab to posixtime' and this was the top result page link.
So you can use the posixtime function.
D1 = 1246573330;
D2 = posixtime(datetime(D1,'ConvertFrom','posixtime'));
D2-D1
ans = 0
@huda nawaf — That depends on the result you want.
format longG
dts = '06-Aug-2005 13:22:50'; % Original
dn = datenum(dts,'dd-mmm-yyyy HH:MM:SS') % MATLAB Date Number
dn =
732530.557523148
dtv = datetime(dts, 'InputFormat','dd-MMM-yyyy HH:mm:ss') % Intermediate 'datetime' Conversion Required For The Following —
dtv = datetime
06-Aug-2005 13:22:50
dtj = juliandate(dtv) % Julian Date
dtj =
2453589.05752315
dtp = posixtime(dtv) % Posix Time
dtp =
1123334570
.
huda nawaf
huda nawaf on 28 Aug 2022
Moved: Steven Lord on 28 Aug 2022
1123334570
this number what i need to get from 06-Aug-2005 13:22:50, but i do not know how get it
@Star Strider thanks so much
This is what I look for
format longG
>> dts = '06-Aug-2005 13:22:50';
>> dtv = datetime(dts, 'InputFormat','dd-MMM-yyyy HH:mm:ss')
>> dtp = posixtime(dtv)
dtp =
1123334570
As always, my pleasure!

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2022a

Tags

Community Treasure Hunt

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

Start Hunting!