Note that uptime has the property that it increases one second per second, exactly. You can read it once and then interpolate based on the current time.
Try applying the time package to your problem, you could parse the string representation of the uptime into a time and then use the packages functionality to do what you want like this: https://play.golang.org/p/Q4W7NJ8SHm9
What can i do to change that string to int ?
I have applied atoi but it shows error as
cannot use parts (type []string) as type string in argument to strconv.Atoi
for scanner.Scan() {
text := scanner.Text()
parts := strings.Split(text, " ")
i, err := strconv.Atoi(parts)
if err != nil {
// handle error
fmt.Println(err)
os.Exit(2)
}
Sorry that I have to say this, but if you are not able to act accordingly on this error message, and you do not know how to make a []string into a string, you really should take the go tour again.
Also, this forum uses markdown to format its code. So you have 3 ways to create a block of code here:
Select the text you want to mark as code in the edit-box and then click the </>-button in the toolbar above the edit-box
Indent each line of the code block by 4 spaces (this is what the button actually does)
Wrap your code in a “fence”. Fences supported from this markdown processor are either at least 3 backticks (```) or at least 3 tilde (~~~). Put them in front and at the end of your codeblock. Eg:
Hi @Bidhan
You would have to range over slice to convert each value in slice to convert to int.
Atoi would work but when you range.
( []string is slice multiple of strings no?)