Get System Date and Time Sample in C

//////////////////////SYSTEM DATE && TIME//////////////
CODE:1-
#include <time.h>
#include <stdio.h>
void main( )
{
 char dbuffer [9];
   char tbuffer [9];
   _strdate( dbuffer );
   printf( "The current date is %s \n", dbuffer );
   _strtime( tbuffer );
   printf( "The current time is %s \n", tbuffer );
}
CODE:2-Find Date Ans Time As Per Your Recquirement
#include <stdio.h>
#include <time.h>
int main ()
{
  time_t rawtime;
  struct tm * timeinfo;
  char buffer [80];
  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  strftime (buffer,80,"TIME_IS:::: %y%m%d%H%M",timeinfo);
  puts (buffer);
 
  return 0;
}
 
/*(SPECIFIER)                            (REPLACED BY)                           (EXAMPLE) %a                                             Abbreviated weekday name              Thu
 %A                                            Full weekday name                           Thursday 
 %b                                           Abbreviated month name                   Aug
 %B                                           Full month name                                August
 %c                                           Date and time representation              Thu Aug 23 14:55:02 2001
 %d                                           Day of the month(01-31)                   23
 %H                                          Hour in 24h format (00-23)                14
 %I                                            Hour in 12h format (01-12)                02
 %j                                            Day of the year (001-366)                  235
 %m                                          Month as a decimal number (01-12)     08
 %M                                            Minute (00-59)                 55
 %p                                            AM or PM designation               PM
 %S                                            Second (00-61)                 02
 %U    Week number with the first Sunday as the first day of week one (00-53)   33
 %w    Weekday as a decimal number with Sunday as 0 (0-6)        4
 %W    Week number with the first Monday as the first day of week one (00-53)   34
 %x                                            Date representation                                                          08/23/01
 %X                                            Time representation                14:55:02
 %y                                            Year, last two digits (00-99)                      01
 %Y                                        Year                   2001
 %Z                                            Timezone name or abbreviation             CDT
 %%                                        A % sign                  %
*/
CODE:2-
#include<stdio.h>
#include<conio.h>
#include <Windows.h>
#include <stdlib.h>
#include<time.h>
void main()
{
 char date[100];
 char s2[100];
 char ax[100];
 int i,j;
    SYSTEMTIME st;
    GetSystemTime(&st);
    printf("Year:%d\nMonth:%d\nDate:%d\nHour:%d\nMin:%d\nSecond:% d\n" ,st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond);
   
}
 

CODE:3-

#include <stdio.h>
#include <time.h>
int main ()
{
    char *date;
   
    time_t timer;
    timer=time(NULL);
   
    date = asctime(localtime(&timer));

    printf("Current Date: %s", date);
    
    getchar();
    return 0;
}

Comments

Popular posts from this blog

Error : DependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.adobe.aem:uber-jar:jar:apis -> version 6.3.0 vs 6.4.0

Operators in Asterisk with Linux

ERROR Exception while handling event Sitecore.Eventing.Remote.PublishEndRemoteEventException: System.AggregateExceptionMessage: One or more exceptions occurred while processing the subscribers to the 'publish:end:remote'