Changing a double type cell in "HH:MM:SS" format.
Mostrar comentarios más antiguos
I have a time column which has a double type, "4.099215427200000e+09" as an example of one cell of the whole column.
Is there a way how to change the whole column format in a date format " HH:MM:SS"?
8 comentarios
Ameer Hamza
el 6 de Oct. de 2020
What is the mapping between 4.099215427200000e+09 and HH:MM:SS?
Ramo Rafsel
el 6 de Oct. de 2020
Editada: Ramo Rafsel
el 6 de Oct. de 2020
Stephen23
el 6 de Oct. de 2020
"There is no mapping between them."
There must be a mapping, otherwise your question is totally meaningless. What is the epoch? What is the unit of time?
Ramo Rafsel
el 6 de Oct. de 2020
Bjorn Gustavsson
el 6 de Oct. de 2020
As I wrote below, matlab uses (used?) time in fractional days since start of year 0. If you feed datestr time from some other starting-point (1970 01 01 00:00:00?) in some other units (seconds for example) datestr will not know about your choise of epoch and unit. You will have to make a conversion from your/excel's time-convention to the time-convention matlab uses.
'If you get to see both screenshots that I uploaded, you ll see the last column on the first picture in Excel that has time formats "13:10:43"...'
We cannot tell from a screenshot what the actual data in that cell is. What is displayed does not tell us much, because displaying data is usually a lossy process which does not represent all of the stored value in memory.
'...which I got with the same procedure that I used in matlab'
Given that you have not described in any way the "procedure" that you attempted, and do not seem to have taken into account the different epochs that these two applications use, I am not surprised that you get very different outputs.
If you want help with this then please upload some sample data (e.g. in an Excel file) and also explain what this mystery "procedure" is. And if at all possible, please tell us the epoch and unit of the timestamp number.
Note: Excel uses fractional days since 1900 or 1904, which means that if we convert todays date into an Excel datenumber we get 44110 (this is what is stored in the cell, how it is formatted is irrelevant). Assuming a standard Excel date, your value of 4099215427.2 would be several thousand years in the future, which seems a bit unlikely... Interpreting it as posix time gives the date 24th of November 2099 at 14:57:07, which seems a bit more likely... but who knows, this is all guessing.
Not telling us the epoch and unit make it very difficult for us to help you.
Ramo Rafsel
el 6 de Oct. de 2020
Bjorn Gustavsson
el 6 de Oct. de 2020
OK, so now you've explained that the time-unit is ms (perhaps?). That takes us to the result that your first data (4.099215427200000e+09) is 47.445 days from your date-zero. If you can tell datestr what that date-zero is you've solved your problem.
Respuesta aceptada
Más respuestas (1)
Bjorn Gustavsson
el 6 de Oct. de 2020
Well you get an output from datestr:
datestr(4.099215427200000e+09,'yyyy mm dd HH:MM:SS')
ans =
'3270 08 21 04:47:59'
You will have to give some additional information about the start of your time-scale, see the help and documentation of datestr, datenum ans datevec. Matlab's date-format is in fractional days since 0-0-0 0:0:0, unix-time is in seconds since 1970 01 01 00:00:00 (IIRC?).
HTH
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!