0

I have included linux/thie.h and used do_gettimeofday() to get the time in seconds in integer type. But I want to convert the result of seconds, minutes, hours to char* type. How can I do this?

Btw, I can't include stdlib.h then use itoa() to convert.

I can read the result in the kernel by using the command dmesg now. But I want to show the result in console by tty and I can only get string from kernel. How can I get the time information(it is variable) from kernel to console.

Zen
  • 1
  • 1
  • 2
  • You mean `itoa` I take it. – Matt Phillips May 28 '13 at 17:13
  • thank you for your answer. I can read the result in the kernel by using the command **dmesg**. But I want to show the result in console by tty and I can only get string from kernel. How can I get the time information(it is variable) from kernel to console. – Zen May 29 '13 at 06:08

1 Answers1

1

There is a function that is in the linux libc and does the same thing as atoi: kstrtol, see http://lxr.free-electrons.com/source/include/linux/kernel.h#L255

EDIT:

For the opposite conversion, use time_to_tm and then s(n)printf to format the string as you wish

Guillaume
  • 2,044
  • 12
  • 11