Jump to content

Date manipulation: Difference between revisions

m (syntax highlighting fixup automation)
Line 453:
 
Note: <code>ctime</code> treats the date as local, so that it is like the timezone information were discarded (to see the passage to daylight saving time I must change the date into March 28... no matter the timezone specified)
 
==={{libheader|Gadget}}===
<syntaxhighlight lang="c">
#include <gadget/gadget.h>
 
LIB_GADGET_START
 
void write_human_date( const char* date, const char * time )
{
Print "%s %d %d %d:%d%s EST\n", Get_monthname( Get_month( date )-1 ),\
Get_day( date ), Get_year( date ), \
Get_hour(time),Get_minute(time), \
Get_hour(time)>12 ? "pm" : "am" ;
}
 
#define Sign(_N_) ( (_N_)<0? -1 : 1 )
 
Main
Assert( Arg_count==2, fail_input );
Get_arg_int( addhour, 1 );
Set_date_lang( EN ); // fix english language
char * date = Get_date();
char * time = Get_time();
addhour = Sign( addhour )*addhour;
write_human_date(date, time);
 
int adddays = ( Time2sec(time) + addhour*60*60 ) / 86400;
Get_fn_let( time, Sec2time( (Time2sec(time) + addhour*60*60 )) );
Get_fn_let( date, Date_add( date, adddays ) );
 
write_human_date(date, time);
Free secure date, time;
 
Exception( fail_input ){
Msg_red("Use:\n addhour <nHours>\n")
}
 
End
</syntaxhighlight>
{{out}}
<pre>
$ ./addhour 12
january 11 2023 17:10pm EST
january 12 2023 5:10am EST
$ ./addhour 24
january 11 2023 17:10pm EST
january 12 2023 17:10pm EST
$ ./addhour 48
january 11 2023 17:10pm EST
january 13 2023 17:10pm EST
$ ./addhour 72
january 11 2023 17:11pm EST
january 14 2023 17:11pm EST
$ ./addhour 0
january 11 2023 17:11pm EST
january 11 2023 17:11pm EST
$ ./addhour 27
january 11 2023 17:16pm EST
january 12 2023 20:16pm EST
$ ./addhour
Use:
addhour <nHours>
 
</pre>
 
=={{header|C sharp|C#}}==
545

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.