do_gettimeofday(&tv1)
current_kernel_time()

do_gettimeofday function returns a value like that when the time was about 21:42: "1260819441.705069"

and current_kernel_time() function returns a value similar to do_gettimeofday's value.

the print code is for tv1:

len += sprintf(buf,"%10i.%06i\n",(int) tv1.tv_sec, (int) tv1.tv_usec);

I don't know what these functions returns which time.
I want to get the time as "21:42"; (sure the time might be as seconds or hour and minute variables)
Is there a function for this ?

I found the function and header file.

#include <asm/rtc.h>

struct rtc_time mytime;

get_rtc_time(&mytime);
	
mytime.tm_hour, mytime.tm_min

//tm_hour, it's UTC time;

you can use these in your module.

if you want more resolution you have this variables.
(
struct rtc_time {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;*
int tm_yday;*
int tm_isdst;*
};


*notused
)

^ that may work for you in this instance, but it's not standard C, and will not be portable. thats a realtime clock library that is often found on linux machines, but is not guaranteed by the C standard.

for standard C that will work everywhere, use the functions "time()", "localtime()", and "asctime()" from the time.h library.

this will print human readable time of your local timezone.

make sure you understand the "time_t" time type and the "struct tm" time structure.


.

^ that may work for you in this instance, but it's not standard C, and will not be portable. thats a realtime clock library that is often found on linux machines, but is not guaranteed by the C standard.

for standard C that will work everywhere, use the functions "time()", "localtime()", and "asctime()" from the time.h library.

this will print human readable time of your local timezone.

make sure you understand the "time_t" time type and the "struct tm" time structure.


.

I am writing a module there is no time.h there is linux/time.h and it has not any localtime function.

It's like:

#include <linux/init.h>         
#include <linux/module.h>       
#include <linux/proc_fs.h>       // proc filesystem 
#include <asm/uaccess.h> 
#include <asm/rtc.h>



MODULE_LICENSE("Dual DSD/GPL");
MODULE_AUTHOR("...");
MODULE_DESCRIPTION("mytime");



int read_proc(char *buf, char **start, off_t offset,
          int count, int *eof, void *data){
int len2;
	struct rtc_time mytime;
	struct timespec tv;
	struct timeval tv1;
 	time_t time_sec;


.........
.......
...

	return len;
}



static int scull_init(void){

  create_proc_read_entry( "mytime",  
                  0,           
                  NULL,        
                  read_proc,   // callback
                  NULL);       //
  return 0;
}



static void scull_exit(void){

  remove_proc_entry( "mytime",   
                 NULL);       
}

module_init(scull_init);
module_exit(scull_exit);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.