News:

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

Main Menu

powershell and utc time aka greenwich london uk

Started by herge, January 16, 2013, 11:14:23 PM

Previous topic - Next topic

herge


Hi are we ready for a rant!

Windows has made a new batch window called powershell.
it has trouble formatting utc time.
you can use get-date and try to use .touniversaltime()
touniversaltime() does work but you can't format it.
i e it is short format i e not long form.
this is long format.

  Wednesday, January 16, 2013 6:42 AM

write-host -nonewline helps a bit but not ideal.
so we used and ancient borland c compiler to fix the
bloody problem.

touniversaltime is similiar to gmtine in the program
below it tells the time in England.
Also MAKE sure you have set the environmental variable
TZ to your Time zone. i e Control Panel, System
do it before you open dos box i e cmd.exe or powershell.



/* GMT.CPP Wednesday, January 16, 2013 4:44 AM   
   Author: Herge
   Location: Waterloo, Ontario, CANADA */
#include<locale>
#include<conio>
  using std::cout;
  using std::time_t;
  using std::asctime;
  using std::gmtime;
  using std::localtime;
  using std::tm;
  using std::strftime;
  int main( int )
{
  struct tm *toc;
  char B [ 128 ];
  time_t t;
  t = time ( NULL );
  toc = gmtime ( &t );
  cout << "GMT[UTC] London England Time is: "
       << asctime ( toc );
  strftime ( B, sizeof ( B ), " %A,%B,%d,%Y %X %p UTC\n",
           gmtime ( &t ) );   
  cout << B;         
  getch( );
  return 0;
}

The extension MUST be ps1 or it will not go!
## utc.ps1 Wednesday, January 16, 2013 1:45 AM
get-date
$a = get-date
$a.touniversaltime()
write-host -nonewline $a.touniversaltime(),"UTC"
write-host
c:\masm32\bin\gmt.exe
## E N D of File utc.ps1

Your first powershell program output below.

Wednesday, January 16, 2013 6:50:02 AM
Wednesday, January 16, 2013 11:50:02 AM
1/16/2013 11:50:02 AM UTC
GMT[UTC] London England Time is: Wed Jan 16 11:50:02 2013
Wednesday,January,16,2013 11:50:02 AM UTC

you have to press a key to stop it.


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

herge

Hi again:
The traffic is killing me but just because powershell is little difficult to use.
And the documentation at the big m$ is at they useless standards.
It it don't work print it anyway. you will need /CLR option to run it.
So heads up!
Tested on 2008 C from Microsoft so please PRAY! and Windows XP SP3
it will complain about localtime but that problem is in 2038 so i think we
can wait another twenty years maybe?

Regard herge


// utc64.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
// utc64.cpp : Defines the entry point for the console application.
// needs /CLR Support managed CODE Change the Project Properties!
//\utc64.cpp(14) : fatal error C1190: managed targeted code requires a '/clr' option

#include "stdafx.h"
#include <iostream>
#include <time.h>
// crt_gmtime64_s.c
// This program uses _gmtime64_s to convert a 64-bit
// integer representation of coordinated universal time
// to a structure named newtime, then uses asctime_s to
// convert this structure to an output string.
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;
using namespace System::Threading;
using namespace::std;
int main(int argc, _TCHAR* argv[])
{ // Must be const wchar_t
   size_t wcsftime(
   const wchar_t *strDest,
   size_t maxsize,
   const wchar_t *format,
   const struct tm *timeptr
);
   struct tm newtime;
   __int64 ltime;
   char buf[128];
   errno_t err;

   _time64( &ltime );
   cout << endl;

   // Obtain coordinated universal time:
   err = _gmtime64_s( &newtime, &ltime );
   if (err)
   {
      cout << "Invalid Argument to _gmtime64_s."
   << endl;
   }
   
   // Convert to an ASCII representation
   err = asctime_s(buf, 26, &newtime);
   if (err)
   {
      cout << "Invalid Argument to asctime_s."
   << endl;
   }

   cout << "Coordinated universal time is "
    << buf << endl;
   strftime ( buf, sizeof ( buf ), "%A %B %d %Y %X %p %Z\n",
           localtime ( &ltime ) );   
   cout << buf;
   strftime ( buf, sizeof ( buf ), "%#c %p %Z\n",
           localtime ( &ltime ) );   
   cout << buf;
   return 0;
}

   

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

dedndave

if you are doing greenwich time, why not use TIME_FORCE24HOURFORMAT

        pushad
        mov     eax,esp
        INVOKE  GetTimeFormat,LOCALE_USER_DEFAULT,TIME_FORCE24HOURFORMAT or TIME_NOTIMEMARKER,NULL,NULL,eax,32
        print   esp,13,10
        add     esp,32

herge

 Hi dedndave:

The problem is that the format options for .touniversaltime()
in powershell totally are sub-standard even for m$.
It was easy for an old c compiler and Borland is really old.

I will try out your code tomorrow.

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

dedndave

GetTimeFormat is actually intended to retrieve the local time format
however, you can also use it to get current local time
it can also be used to format time, according to a format string

GetSystemTime can be used to get UTC (GMT) time and store it in a SYSTEMTIME structure
you can then use GetTimeFormat with a format string to format it
http://msdn.microsoft.com/en-us/goglobal/bb688125.aspx

herge


Hi dedndave:

That was not bad, only forgot the environmental variable
TZ .I suspect if you don't come from a DOS old OS you
will never heard of it.
I am in EST are you in MST or PST? (Time Zone)
It is a Canadian invention something to do with
the RailRoads if my memory is any good.

Regards herge

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

dedndave

i am in MST
in Arizona, we do not use daylight savings time

i am not sure what part you are refering to as a Canadian invention
time zones were around long before trains   :biggrin:

herge


Hi dedndave:

Yes I am wrong but is something to do with Railways in England
according to Wiki.
If it is any thing to do with British Rail we are in deep Sh*t!

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

dedndave

you may be right, as far as "official time zones"
but - the correct time was critical to navigating ships in days of old
as i recall, they tried to have a very accurate clock that kept London time
(actually, it was Greenwich time, the 0 meridian line passes through Greenwich)
the more accurate your clock, the closer you could determine your longitude

that was before Einstein got involved
he proved that a clock in motion kept time differently than one that was stationary   ::)

herge


Hi dedndave:

They was a bad Helicopter crash in
London England. He hit a Building crane
in the fog. It took me for ever and a day
to download BBC story.

Bye Now DND code for department of National Defense
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

dedndave


dedndave

that didn't seem like a logical coarse of events
i knew that the concept of "daylight savings time" was Ben Franklin's idea
and - trains came after Ben   :P

herge

 
Hi dedndave:

According to Google , Fleming was Scottish or a Canadian
and did something for the Railways in Canada. Died before
the  end of first world war.

Assembly History is so intresting!

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

dedndave


herge

Hi dedndave:

That's intresting my Dad use to install RADAR for Raytheon
before he retired. Also a minor American use to work on the
Telegraph in a Railway station in Stratford, Ontario
some bloke named Edison?

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