News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

DATE & TIME VC 2008

Started by herge, July 04, 2015, 04:28:49 PM

Previous topic - Next topic

herge

Hi:

Shows date and time.


.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
/* TIMPTR.CPP Sunday, December 28, 2008 4:09 PM
   Author: Herge
   Location: Waterloo, Ontario, CANADA*/
#include <iostream>
#include <iomanip>
#include <time.h>
#include <conio.h>
using std::cout;
using std::setw;
using std::setfill;
using std::endl;
  int main( )
  {
  char buf [ 128 ];// TimePtr
  const char* MonthNum[ ] = {
  "Zero","First","Second","Third","Fourth","Fifth","Sixth","Seventh",
  "Eighth","Ninth","Tenth","Eleventh","Twelveth","Thirteenth",
  "Fourteenth","Fifteenth","Sixteenth","Seventeenth",
  "Eighteenth","Nineteenth","Twentyth","Twenty First",
  "Twenty Second","Twenty Third","Twenty Fourth",
  "Twenty Fifth","Twenty Sixth","Twenty Seventh",
  "Twenty Eightth","Twenty Nineth","Thirty",
  "Thirty First"};
  const char* DayName [ ] = {
  "Sunday","Monday","Tuesday","Wednesday",
  "Thursday","Friday","Saturday"}; 
   const char* MonthNam[ ] = {
   "January","February","March","April",
   "May","June","July","August",
   "September","October","November","December"};
   time_t t;
   t = time(0);
   tm* P = localtime ( &t );
   cout << setw(2) << setfill('0') << P-> tm_mon + 1 << "/"
        << setw(2) << P-> tm_mday << "/"
        << setw(2) << P-> tm_year  % 100 << " ";
   cout << setw(2) << P-> tm_hour << ":"
        << setw(2) << P-> tm_min << ":"
        << setw(2) << P-> tm_sec << endl;
   cout << "IS DAYLIGHT STANDARD TIME tm_isdst " << P-> tm_isdst  << " tm_wday " <<  P-> tm_wday
        << endl;
   cout << DayName[  P-> tm_wday ] << " "
        << MonthNum [P-> tm_mday]
        << " of " << MonthNam[  P-> tm_mon] << ", "
        << 1900 + P-> tm_year << " " << setw(2)
<< P-> tm_hour << ":" << setw(2) << P-> tm_min
<< ":" << setw(2) << P-> tm_sec << endl;
    /*
      >SET TZ=EST+5EDT
      In a Dos Box ie Command Prompt set TZ to
      your Time Zone. This is for Eastern Standard Time.
      The %Z will Not work if TZ is not set before.
      IE Toronto, New York City are in EST.
  */
      strftime ( buf , sizeof(buf) , "%Z Time is ... %#c\n", localtime ( &t ) );
      cout << buf;
      strftime ( buf , sizeof(buf) , "%Z Time is ... %A, %B, %d , %Y %X %p\n", localtime ( &t ) );
      cout << buf;
      strftime ( buf , sizeof(buf) , "UTC Time is ... %a, %b, %d , %Y %X %p\n", gmtime ( &t ) );
      cout << buf;
      strftime ( buf , sizeof(buf) , "%Z Time is ... %p %H %M %S, %A, %b, %d , %Y %X %p\n", localtime ( &t ) );
      cout << buf;
      strftime ( buf , sizeof(buf) , "%Z Time is ... %x %X %p\n", localtime ( &t ) );
      cout << buf;
      strftime ( buf , sizeof(buf) , "%Z Time is ... %c %p\n", localtime ( &t ) );
      cout << buf;
      strftime ( buf , sizeof(buf) , "%A P-> tm_wday ", localtime ( &t ) );
      cout << buf << P-> tm_wday;
      cout << " \nPress Any Key ... \n";
      getch();
      return 0;
  }



C:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\TimePtr
\Debug>timeptr
07/04/15 02:15:26
IS DAYLIGHT STANDARD TIME tm_isdst 1 tm_wday 6
Saturday Fourth of July, 2015 02:15:26
EDT Time is ... Saturday, July 04, 2015 02:15:26
EDT Time is ... Saturday, July, 04 , 2015 02:15:26 AM
UTC Time is ... Sat, Jul, 04 , 2015 06:15:26 AM
EDT Time is ... AM 02 15 26, Saturday, Jul, 04 , 2015 02:15:26 AM
EDT Time is ... 07/04/15 02:15:26 AM
EDT Time is ... 07/04/15 02:15:26 AM
Saturday P-> tm_wday 6
Press Any Key ...

C:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\TimePtr
\Debug>


Regards Herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

herge

#1
 Hello:
By popular demand, No but just I could bearly read the
output. I did a couple of reads of Microsoft Documents
on the intermet and come up with a Brighter Ouput.

Note the Environmental Variable TZ MUST be SET before
or %Z will not work. SET in DOS i e Command Promt or
Conrol Panel.


// MASM32time.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <iomanip>
#include <time.h>
#include <conio.h>
using std::cout;
using std::setw;
using std::setfill;
using std::endl;
int _tmain(int argc, _TCHAR* argv[])
  {
  CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  HANDLE hStdout, hStdin;
  WORD wOldColorAttrs;
  char buf [ 128 ];
  const char* MonthNum[ ] = {
  "Zero","First","Second","Third","Fourth","Fifth","Sixth","Seventh",
  "Eighth","Ninth","Tenth","Eleventh","Twelveth","Thirteenth",
  "Fourteenth","Fifteenth","Sixteenth","Seventeenth",
  "Eighteenth","Nineteenth","Twentyth","Twenty First",
  "Twenty Second","Twenty Third","Twenty Fourth",
  "Twenty Fifth","Twenty Sixth","Twenty Seventh",
  "Twenty Eightth","Twenty Nineth","Thirty",
  "Thirty First"};
  const char* DayName [ ] = {
  "Sunday","Monday","Tuesday","Wednesday",
  "Thursday","Friday","Saturday"}; 
   const char* MonthNam[ ] = {
   "January","February","March","April",
   "May","June","July","August",
   "September","October","November","December"};
   hStdin = GetStdHandle(STD_INPUT_HANDLE);
   hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
   if (! GetConsoleScreenBufferInfo(hStdout, &csbiInfo))
    {
        MessageBox(NULL, TEXT("GetConsoleScreenBufferInfo"),
            TEXT("Console Error"), MB_OK);
        return 1;
    }
   wOldColorAttrs = csbiInfo.wAttributes; // save old colors
   if (! SetConsoleTextAttribute(hStdout, 15))
   { // 15 intensified WHITE
        MessageBox(NULL, TEXT("SetConsoleTextAttribute"),
            TEXT("Console Error"), MB_OK);
        return 1;
    }         
   time_t t;
   t = time(0);
   tm* P = localtime ( &t );
   cout << setw(2) << setfill('0') << P-> tm_mon + 1 << "/"
        << setw(2) << P-> tm_mday << "/"
        << setw(2) << P-> tm_year  % 100 << " ";
   cout << setw(2) << P-> tm_hour << ":"
        << setw(2) << P-> tm_min << ":"
        << setw(2) << P-> tm_sec << endl;
   cout << "IS DAYLIGHT STANDARD TIME tm_isdst " << P-> tm_isdst  << " tm_wday " <<  P-> tm_wday
        << endl;
   cout << DayName[  P-> tm_wday ] << " "
        << MonthNum [P-> tm_mday]
        << " of " << MonthNam[  P-> tm_mon] << ", "
        << 1900 + P-> tm_year << " " << setw(2)
<< P-> tm_hour << ":" << setw(2) << P-> tm_min
<< ":" << setw(2) << P-> tm_sec << endl;
    /*
      >SET TZ=EST+5EDT
      In a Dos Box ie Command Prompt set TZ to
      your Time Zone. This is for Eastern Standard Time.
      The %Z will Not work if TZ is not set before.
      IE Toronto, New York City are in EST.
  */
      strftime ( buf , sizeof(buf) , "%Z Time is ... %#c\n", localtime ( &t ) );
      cout << buf;
      strftime ( buf , sizeof(buf) , "%Z Time is ... %A, %B, %d , %Y %X %p\n", localtime ( &t ) );
      cout << buf;
      strftime ( buf , sizeof(buf) , "UTC Time is ... %a, %b, %d , %Y %X %p\n", gmtime ( &t ) );
      cout << buf;
      strftime ( buf , sizeof(buf) , "%Z Time is ... %p %H %M %S, %A, %b, %d , %Y %X %p\n", localtime ( &t ) );
      cout << buf;
      strftime ( buf , sizeof(buf) , "%Z Time is ... %x %X %p\n", localtime ( &t ) );
      cout << buf;
      strftime ( buf , sizeof(buf) , "%Z Time is ... %c %p\n", localtime ( &t ) );
      cout << buf;
      strftime ( buf , sizeof(buf) , "%A P-> tm_wday ", localtime ( &t ) );
      cout << buf << P-> tm_wday;
  SetConsoleTextAttribute(hStdout, wOldColorAttrs);
      cout << " \nPress Any Key ... \n";
      getch();
      return 0;
  }


I have found out tm_mon is 0 to 11 Not 1 to 12.
Also a program to find your 15 attribute a very short program.


; TEXTCOL.ASM 9:12:44 PM Saturday, September 13, 2008
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
    first dd 0
    num   dd 0
    public sZNum
    sZNum db 20 dup(?),0
    db 0
    CRLF    db 13,10
    db 0
    .code
start proc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««


    mov     eax, 255
    mov     ebx, 1
    mov     ecx, 254
StartA:
    push    eax
    push    ebx
    push    ecx
    mov     first, eax    
    invoke SetTextColor, eax, ebx
    print "XXXXXXX "
    .if first == 8
    invoke SetTextColor, 15, 1
    .endif
    invoke crt__ultoa, first, addr sZNum, 10
    invoke StdOut, addr sZNum
    print " "
    invoke crt__ultoa, ebx, addr sZNum, 10
    invoke StdOut, addr sZNum
    invoke SetTextColor, 7, 0
    invoke StdOut, addr CRLF
    inc     num
    cmp     num, 16
    jnz     @F
    mov     num,0
    invoke crt__ultoa, ebx, addr sZNum, 10
    invoke SetTextColor, 15, 1
    inkey
@@:
    pop     ecx
    pop     ebx
    pop     eax
    dec     eax
    inc     ebx
    dec     ecx
    jnz     StartA
    invoke SetTextColor, 15, 0
    inkey
    exit
start endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
SetTextColor proc fore:DWORD,back:DWORD

    LOCAL hStdOut:DWORD
    invoke GetStdHandle,STD_OUTPUT_HANDLE
    mov   hStdOut,eax
    mov   eax,back
    shl   eax,4
    or    eax,fore
    invoke SetConsoleTextAttribute,hStdOut,eax
    ret
SetTextColor endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start



Herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

herge

HI C users:

For Quieter Builds and to SHUT UP the compiler try this.
Edit stdafx,h like so. e g


// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include "targetver.h"

#include <stdio.h>
#include <tchar.h>



// TODO: reference additional headers your program requires here



It makes for very quiet Builds and kills a lot of warnings!

Enjoy!

Herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

Magnum

Is your code an improvement over the date command ?

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org