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 commentaires

Rik
Rik le 23 Août 2022
Which date format is this number representing? The Unix epoch?
huda nawaf
huda nawaf le 23 Août 2022
Unix time stamp

Connectez-vous pour commenter.

 Réponse acceptée

Star Strider
Star Strider le 23 Août 2022
Déplacé(e) : Steven Lord le 23 Août 2022
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 commentaires

huda nawaf
huda nawaf le 23 Août 2022
This is work
DT3 = datetime(D, 'ConvertFrom','posixtime')
But I do not know, what the othors represent
Star Strider
Star Strider le 23 Août 2022
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
huda nawaf
huda nawaf le 24 Août 2022
I means those
DT1 = datetime(D, 'ConvertFrom','datenum')
DT2 = datetime(D, 'ConvertFrom','excel')
DT4 = datetime(D, 'ConvertFrom','juliandate')
But steven clarified it
Star Strider
Star Strider le 24 Août 2022
O.K. Good!
huda nawaf
huda nawaf le 28 Août 2022
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 le 28 Août 2022
Déplacé(e) : Steven Lord le 28 Août 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
Star Strider
Star Strider le 28 Août 2022
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2022a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by