Convert decimal day to HH:MM
Try this:
R> format(as.POSIXct(Sys.Date() + 0.8541667), "%H:%M", tz="UTC")
[1] "20:30"
R>
We start with a date--which can be any date, so we use today--and add your desired fractional day.
We then convert the Date type into a Datetime object.
Finally, we format the hour and minute part of the Datetime object, ensuring that UTC is used for the timezone.
Work time calc - How to convert decimal to hh:mm ?
If you want to include total hours (so that it will convert whole days to hours too), you can do it like that:
String.Format("{0:D2}:{1:D2}", (int)workTime.TotalHours, workTime.Minutes);
How to convert a decimal number to numbers in days, hours, and min in Excel
Use:
=INT(A2/24) & "d " & TEXT(A2/24,"h\h m\m")
Convert decimal Day-of-year dataframe to datetime with HH:MM
Use Timedelta
to create an offset from the first day of year
Input data:
>>> df
DayOfYear
0 254
1 156
2 303
3 32
4 100
5 8
6 329
7 82
8 218
9 293
df['Date'] = pd.to_datetime('2021') \
+ df['DayOfYear'].sub(1).apply(pd.Timedelta, unit='D')
Output result:
>>> df
DayOfYear Date
0 254 2021-09-11
1 156 2021-06-05
2 303 2021-10-30
3 32 2021-02-01
4 100 2021-04-10
5 8 2021-01-08
6 329 2021-11-25
7 82 2021-03-23
8 218 2021-08-06
9 293 2021-10-20
How to convert decimal hour value to hh:mm:ss
You could do something like this:
var decimalTimeString = "1.6578";
var decimalTime = parseFloat(decimalTimeString);
decimalTime = decimalTime * 60 * 60;
var hours = Math.floor((decimalTime / (60 * 60)));
decimalTime = decimalTime - (hours * 60 * 60);
var minutes = Math.floor((decimalTime / 60));
decimalTime = decimalTime - (minutes * 60);
var seconds = Math.round(decimalTime);
if(hours < 10)
{
hours = "0" + hours;
}
if(minutes < 10)
{
minutes = "0" + minutes;
}
if(seconds < 10)
{
seconds = "0" + seconds;
}
alert("" + hours + ":" + minutes + ":" + seconds);
Converting decimal time (HH.HHH) into HH:MM:SS in Python
You do not have to use datetime
. You can easily compute hours, minutes and seconds from your decimal time.
You should also notice that you can use string formatting which is really easier to use than string concatenation.
time = 72.345
hours = int(time)
minutes = (time*60) % 60
seconds = (time*3600) % 60
print("%d:%02d.%02d" % (hours, minutes, seconds))
>> 72:20:42
Related Topics
Get the Event Which Is Fired in Shiny
Replace Value with the Name of Its Respective Column
Combining Low Frequency Counts
R: Updating a Data Frame with Another Data Frame
Ggplot2 Overlay of Barplot and Line Plot
How to Convert Time to Decimal
Calculating a Distance Matrix by Dtw
Real Cube Root of a Negative Number
In R Combine a List of Lists into One List
Connect to Redshift via Ssl Using R
Font Family Won't Change in Ggplot
Documentation on Internal Variables in Ggplot, Esp. Panel
R - Faster Way to Calculate Rolling Statistics Over a Variable Interval