How do you parse a millisecond number into HH:MM:SS - basic4android

Can you tell me how to parse a millisecond number such as 10173510 into hours, minutes and seconds?
Formated like this maybe?
HH:MM:SS
Thanks.
Update:
I was able to get it close but I need to format the numbers correctly because I need leading zeros (0) to make the results look something like this: 01:52:03 because the code shows 1:52:3 instead.
Sub SeekBarTimeToKeepActive_ValueChanged (Value As Int, UserChanged As Boolean)
Dim intHoursToKeepActive As Int
Dim intMinutesToKeepActive As Int
Dim intSecondsToKeepActive As Int
intHoursToKeepActive = DateTime.GetHour(Value) -19
intMinutesToKeepActive = DateTime.GetMinute(Value)
intSecondsToKeepActive = DateTime.GetSecond(Value)
LabelTimeToKeepActive.Text = "Length of time to keep active: " & _
intHoursToKeepActive & ":" & intMinutesToKeepActive & ":" & intSecondsToKeepActive
End Sub

Try using Number Format:
Example:
Hour = 2
NumberFormat(hour,2,0)

Related

Need to convert or format hhmmss to hh-mm-ss using powershell [duplicate]

I'm creating an application in PowerShell to reschedule the existing jobs in a SQL Server instance. So I have to get the active_start_time value from the sysschules table. The time value is formatted as INT HHMMSS on a 24-hour clock.
As I am using the JobSchedule class (Microsoft.SqlServer.Management.Smo.Agent.JobSchedule) in my PowerShell application, I need to convert from time value in INT to a TimeSpan value in order add to ActiveStartTimeOfDay property.
Example:
Original data: [INT] active_start_time = 10500
Expected data: [TimeSpan] ActiveStartTimeOfDay = 01h 05 min 00s
As FoxDeploy points out, treat the input number as a string!
First, you'll want to use String.PadLeft() to zero-pad the number:
$active_start_time = 10500
$start_timestamp = "$active_start_time".PadLeft(6, '0') # "010500"
Now that we have a "timestamp" of sorts, [timespan] has a ParseExact() method we can use to parse any format:
$start_timespan = [timespan]::ParseExact($start_timestamp, 'hhmmss', $null)
We can do this by taking your input int and treating it like a string. Doing that lets us call ToCharArray() which does this.
$myString = "Hi!"
$myString.ToCharArray()
H
i
!
Once it's in a char array, we can select out the positions of the characters we want by specifying its index, starting with zero, like this:
PS> $myString.ToCharArray()[0] #get's the first
H
Applying that to your scenario, we do the same to select only the numbers we want and tuck them into variables to call on later. With that, we can easily build a new [TimeSpan] object.
$inputInt = 121515
$hours= $inputInt.ToString().ToCharArray()[0..1] -join ''
$mins= $inputInt.ToString().ToCharArray()[2..3] -join ''
$secs = $inputInt.ToString().ToCharArray()[4..5] -join ''
$hours,$mins,$secs -join ":"
Output> 12:15:15
There are a lot of options to make a new [TimeSpan], we can see our choices by typing the static class name and method, and seeing what comes up.
PS> [timespan]::new
OverloadDefinitions
-------------------
timespan new(long ticks)
timespan new(int hours, int minutes, int seconds)
timespan new(int days, int hours, int minutes, int seconds)
timespan new(int days, int hours, int minutes, int seconds, int milliseconds)
That second one looks promising...
$newTimeSpan = [TimeSpan]::new($hours,$mins,$secs)
$newTimeSpan
This should get you heading in the right direction.

Parse military time to double in flutter

I am trying to convert a textfield input of military time into a double. Can anyone help me with this? goal would be if someone enters 13:45 then the output would be 13.75.
Divide your input into 2 halves around the :. Then parse each half, which results in separate hours and minutes ints. Add them together, dividing the minutes by 60 to get your intended double output.
String input = "13:45";
String firstHalf = input.substring(0, input.indexOf(':'));
String secHalf = input.substring(input.indexOf(':') + 1);
int hour = int.parse(firstHalf);
int min = int.parse(secHalf);
double output = hour + min/60;
print(output);//13.75

Converting time to milliseconds?

I have some time as string format in my data. Can anyone help me to convert this date to milliseconds in Matlab.
This is an example how date looks like '00:26:16:926', So, that is 0 hours 26 minutes 16 seconds and 926 milliseconds. After converting this time, I need to get only milliseconds such as 1576926 milliseconds for the time that I gave above. Thank you in advance.
Why don't you try using datevec instead? datevec is designed to take in various time and date strings and it parses the string and spits out useful information for you. There's no need to use regexp or split up your string in any way. Here's a quick example:
[~,~,~,hours,minutes,seconds] = datevec('00:26:16:926', 'HH:MM:SS:FFF');
out = 1000*(3600*hours + 60*minutes + seconds);
out =
1576926
In this format, the output of datevec will be a 6 element vector which outputs the year, month, day, hours, minutes and seconds respectively. The millisecond resolution will be added on to the sixth element of datevec's output, so all you have to do is convert the fourth to sixth elements into milliseconds and add them all up, which is what is done above. If you don't specify the actual day, it just defaults to January 1st of the current year... but we're not using the date anyway... we just want the time!
The beauty with datevec is that it can accept multiple strings so you're not just limited to a single input. Simply put all of your strings into a single cell array, then use datevec in the following way:
times = {'00:26:16:926','00:27:16:926', '00:28:16:926'};
[~,~,~,hours,minutes,seconds] = datevec(times, 'HH:MM:SS:FFF');
out = 1000*(3600*hours + 60*minutes + seconds);
out =
1576926
1636926
1696926
One solution could be:
timeString = '00:26:16:926';
cellfun(#(x)str2num(x),regexp(timeString,':','split'))*[3600000;60000;1000;1]
Result:
1576926
Assuming that your date string comes in that format consistently, you could use something as simple as this:
test = '00:26:16:926';
H = str2num(test(1:2)); % hours
M = str2num(test(4:5)); % minutes
S = str2num(test(7:8)); % seconds
MS = str2num(test(10:12)); % milliseconds
totalMS = MS + 1000*S + 1000*60*M + 1000*60*60*H;
Output:
1576926.00
you can convert a single string with a date or even a vector by using datevec for conversion and the dot product
a = ['00:26:16:926' ; '08:42:12:936']
datevec(a,'HH:MM:SS:FFF') * [0 0 0 3600e3 60e3 1e3]'
ans =
1576926
31332936

How to convert numbers in to date?

Bij splitting a string an array gives me following values back:
araay[1]=2
araay[2]=9
array[3]=2014
My question is how can i make from these 3 numbers a date 2-9-2014.
If i try:
var date = (array[1]-array[2]-array[3])
the return value is -2021 This is 2-9-2014=2021
var date = new Date (array[1]-array[2]-array[3])
the return value is 2
var date = new Date (array[1]-array[2]-array[3])
the reutrun value is 4-4-1908
So who can solve this?
Read basic string or char functionality for your chosen language.
Also this can be put in a class, predefined or not.
First you can try to use the - as chars instead of operators..
date = array[1] + "-" + array[2] + "-" + array[3]
but you should seriously just look at some documentation..
http://en.cppreference.com/w/

Get date from Unix Timestamp in Metro style App

Iam reading out a Json file with a date in it.
jsonValue->GetObject()->GetNamedObject("board")->GetNamedNumber("date")
That date is saved in Unix code format:
"date":1347973494
But I need to get it in a normal format like "19.09.2012".
I cant find the right function to solve that problem.
I already tried the DateTimeFormatter class but I think that was not the correct way to make this.
So anyone knows how to change the DateTime from Unix timestamp to a normal format like "19.09.2012"?
A Unix timestamp is seconds since 1970, so add the seconds to 1970-01-01.
int unixTimestamp = 1347973494;
System::DateTime timestamp = System::DateTime(1970, 1, 1).AddSeconds(unixTimestamp);
Then format the DateTime into whatever string format you like, or use it as a DateTime.
System::String^ formatted = timestamp.ToString("dd.MM.yyyy")
I solved the problem with the Calendar class which you can find here
int unixTimestamp = (int)jsonValue->GetObject()->GetNamedNumber("date");
Windows::Globalization::Calendar^ cal = ref new Windows::Globalization::Calendar();
cal->Year = 1970;
cal->Month = 1;
cal->Day = 1;
cal->Minute = 0;
cal->Hour = 0;
cal->Second = 0;
cal->AddSeconds(unixTimestamp);
mainDate -> Text = cal->DayAsString() + ". " + cal->MonthAsString() + " " + cal->YearAsString();