The MASM Forum

Specialised Projects => Compiler Based Assembler => Assembler With Microsoft Visual C => Topic started by: herge on January 16, 2013, 11:14:23 PM

Title: powershell and utc time aka greenwich london uk
Post by: herge on January 16, 2013, 11:14:23 PM

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
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 17, 2013, 08:23:41 AM
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;
}

   

Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on January 17, 2013, 10:45:56 AM
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
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 17, 2013, 12:31:54 PM
 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
Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on January 17, 2013, 12:45:24 PM
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 (http://msdn.microsoft.com/en-us/goglobal/bb688125.aspx)
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 17, 2013, 01:07:48 PM

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

Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on January 17, 2013, 01:11:15 PM
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:
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 17, 2013, 01:24:05 PM

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
Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on January 17, 2013, 01:27:10 PM
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   ::)
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 17, 2013, 01:45:07 PM

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
Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on January 17, 2013, 01:50:51 PM
you were right -
railways had something to do with it...

http://www.timeanddate.com/time/time-zones-history.html (http://www.timeanddate.com/time/time-zones-history.html)
Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on January 17, 2013, 02:04:47 PM
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
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 17, 2013, 02:11:48 PM
 
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
Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on January 17, 2013, 02:21:03 PM
here you go...

http://en.wikipedia.org/wiki/Sandford_Fleming (http://en.wikipedia.org/wiki/Sandford_Fleming)

a different guy named Fleming, that i am familiar with   :P

http://en.wikipedia.org/wiki/John_Ambrose_Fleming (http://en.wikipedia.org/wiki/John_Ambrose_Fleming)
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 17, 2013, 02:37:39 PM
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
Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on January 17, 2013, 04:04:44 PM
not a big fan of edison
i think he stole more ideas than he originated - lol

he did, however, invent the light bulb and the cylindrical phonograph
the cylinders may have done better, but he wouldn't sell any rag-time music - only conservative music
with disks, you could get the music you wanted to hear, so they caught on
they probably would have taken over eventually, anyways, because they were easier to store and handle
but cylinders do offer a slight technical advantage in that the track has constant length

another guy, DeForest, added the control grid to the Fleming Valve
that is what really made tubes do something
before that, they were just rectifiers
with a control grid, they could be used to amplify - a big step
Brits still call them "valves", though   :P

at the turn of the century, there was a lot of patent grabbing going on, with regard to electrical discovery
also - a lot of mud-slinging - anything to discredit the opposition
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 17, 2013, 07:31:36 PM
  Thursday, January 17, 2013 3:25 AM EST

Hi dedndave:

He made a light bulb that you could use, the first light bulb did
not last very long?
Did all sort of electrical work i e Con Edison I hopte I got the
name right.
HMV his master's Voice the fore rumber of a thing we call the
MP3

Regards herge
Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on January 17, 2013, 11:28:38 PM
this is true - the first light bulb didn't last long at all
he found a filament alloy, largely by trial and error, that lasted

edison is credited with many patents
i think he still holds more patents than any other individual
this may have changed - i'm not sure
but, most of his patents were based on someone else's work
he knew more about the patent process than most people at the time
that would make him more of a patent lawyer than an inventor - lol

the fore-runner of MP3's...
you are thinking of Alexander Graham Bell   :P
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 18, 2013, 12:05:34 AM

Hi dedndave:

Bell another Canadian, but I was thinking about Morse the
telegraph guy which connects back to Thomas Edison.

Regards herge
Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on January 18, 2013, 12:10:15 AM
there were many innovators at that time
each built on the discoveries of the others
and, they fought over money every step of the way - lol

some were "advanced experimenters", some were true scientists
it took the work of both to get where we are today
Title: Re: powershell and utc time aka greenwich london uk
Post by: MichaelW on January 18, 2013, 03:46:29 AM
Edison's resistance to AC power was extremely shortsighted, and "unscientific".
Title: Re: powershell and utc time aka greenwich london uk
Post by: FORTRANS on January 18, 2013, 05:09:37 AM
Quote from: dedndave on January 17, 2013, 01:11:15 PM
i am in MST
in Arizona, we do not use daylight savings time

Hi Dave,

   You are lucky.  DST is silly unless you own a golf range.

Cheers,

Steve
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 26, 2013, 02:16:21 AM

Hi Powershell Fans:
## GMT aka UTC aka Time in ye old London town England(UK)
Write-host(get-date -date -format U),"UTC"


Also always save as "Filename.PS1"
some editors have a nasty habit of adding .txt
The quotes are important!
so you get London.PS1.TXT and Powerdhell Goes Nuts
You will get four lines of gibberish that will not help you!
# is a comment marker ie a short REM.

Regards herge
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 26, 2013, 06:43:35 AM
 Hi EveryBody:

## London.PS1 Thursday, January 24, 2013 1:16:27 PM
# Get London Time aka UTC aka GMT
write-host (get-date -format U),"UTC"
# E N D of F I L E


## London.PS1 Thursday, January 24, 2013 1:16:27 PM
# Get London Time aka UTC aka GMT
write-host (get-date -format U),"UTC"
# E N D of F I L E
#
# PS C:\> Set-ExecutionPolicy RemoteSigned
# Even If you are God or Admin Do this First
# This allows the PS1 Files to go!

#
#To sign the Add-Signature.ps1 script file, type the following commands at
#the Windows PowerShell command prompt:

#   $cert = @(Get-ChildItem cert:\CurrentUser\My -codesigning)[0]

#   Set-AuthenticodeSignature add-signature.ps1 $cert
# If it don't Go Try This
# PS C:\> Set-ExecutionPolicy RemoteSigned
# Even If you are God or Admin Do this First
# This allows the PS1 Files to go!
Alway Quote File Names i e "FILENAME.ps1"
SOMETIMES yOU WILL GET "FILENAME.PS1.TXT"
which will not make Powershell or you Happy.
Added Quote the FileName.

Regards herge
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 27, 2013, 05:46:50 PM
 Hi Everbody:

Greetings Windows Powershell Fans.


## itime.ps1 Monday, January 14, 2013 1:27 PM
#Local Time with offset from Zulu (London)
get-date -uformat "%T %p UTC%Z" # Same as C,C++ %etc


You MUST set the environment variable TZ to your Time Zone
or the %Z will not work.


/*
    >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.
    Toronto/Buffalo time.
    */



Regards herge
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 28, 2013, 05:23:32 AM
 
Oh my God:

Powershell can inkey or pause or getch.
Code From Microsoft.

## Inkey.ps1 Saturday, January 26, 2013 12:38:29 PM
Write-Host "Press any key to continue ..."

$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")


Regards herge
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on January 29, 2013, 12:53:23 AM

Hi Everybody:

Because of problems in Powershell ISE it might be quicker
to use Read-host.


# The Get-Host Does Not work in ISE
Read-Host -prompt "Press any Key to Continue"



## Inkey.ps1 Saturday, January 26, 2013 12:38:29 PM
Write-Host "Press any key to continue ..."
#$z = (get-host).UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
# The Get-Host Does Not work in ISE
Read-Host -prompt "Press any Key to Continue" # You Get a Pop up window
# E N D of File


Regards herge
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on February 01, 2013, 09:24:04 PM
 Hi EveryBody:


## about.ps1 Friday, February 01, 2013 4:46 AM
help about_Comparison_Operators > \helpPS1\com_ope.txt
help about_For > \helpPS1\forps1.txt
help about_Foreach > \helpPS1\foreach.txt
help about_Switch > \helpPS1\switch.txt
help about_While > \helpPS1\while.txt


It will create the directory HelpPs1 on the drive you are on.
It will write files to this directory or create it if missing.
But will not warn you if directory is already There!
This will save some scrolling.
use set-location \helpPs1
to get to your directory.
\helpPS1

Regards herge
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on February 02, 2013, 07:37:12 PM

Hi PowerShell Fans:

Finally found something like old DOS type
command.


more c:\masm32\include\windows.inc


Hit Control C you will be here all day
other wise. Windows.inc is massive.

Regards herge
Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on February 03, 2013, 12:14:33 AM
yes - i think DOS had a "filter" called more.exe
type myfile.txt | more.exe
or
copy myfile.txt | more.exe con
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on February 03, 2013, 12:24:37 AM

Hi DednDave:

Yes ir did it took me a long time to find it
I just wanted a listing of a file.
I think they changed all the rules
for powershell.
They was dir /p (dos)which more or less
paused the output.

Regards herge
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on February 03, 2013, 06:26:43 PM
 Hi DednDave:



C:\Documents and Settings\User>copy c:masm32\showtim.asm | more con
Cannot access file \\.\con

C:\Documents and Settings\User>


It also eats memory like a pig do not try on very large files
you get an out of memory error i e windows.inc
The more is not working I never had to hit space bar
once. It stops listing when it runs out and you can
not scroll up to start of file.
The
  type filename.ext | more


works for me.

Regards herge

Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on February 03, 2013, 11:42:46 PM
i may have the order wrong - lol
i am not as proficient with dos commands as i used to be   :P
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on February 25, 2013, 09:43:44 PM
 Hi DednDave:

I final got it go and in German to with a little help
from some assembler pals.


; 24HR.ASM 11:46 AM 6/23/2008
include \masm32\include\masm32rt.inc

.data
public dtbuf
dtbuf db 260 dup(0)
AppName db "Datum und Uhrzeit in der deutschen:", 0
crlf db 13, 10, 0
tf db "HH':'mm':'ss", 0
.code
start proc
invoke GetDateFormat, 1031, DATE_LONGDATE, 0, 0, addr dtbuf, 260
      lea   esi, offset dtbuf
      add   esi , eax  ; eax is len of format
      mov   byte ptr [ esi - 1 ] , " "
      pushad
      mov     eax,esp
      INVOKE  GetTimeFormat,LOCALE_USER_DEFAULT,TIME_FORCE24HOURFORMAT,NULL,NULL, esi,32
      add     esp,32
pop esi
invoke MessageBox, NULL, addr dtbuf, addr AppName, MB_OK
exit
      ret
start endp
    end start



It has not got pass 12 am yet so I am not
100% sure it works yet. But is compiled great.
It does work in the afternoon.
Used Google translate to germanize the title
hope it's clean.
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on March 04, 2013, 12:45:08 AM

Hi Rubber Duck Fans:

By popular demand well just me.
Warning this program uses a kludge i e we cheat.
We get UTC time aka GMT or London England time.
Then we add one to hour to get GMT + 1.
I do not recommend running this program @ 23:00 or 11 PM CET i e German Time.

; 24HR.ASM 11:46 AM 6/23/2008
include \masm32\include\masm32rt.inc

.data
stm    SYSTEMTIME<>
public dtbuf
dtbuf db 260 dup(0)

AppName db "Datum und Uhrzeit in der deutschen:", 0
crlf db 13, 10, 0
tf db "HH':'mm':'ss", 0
.code
start proc
      mov   esi, offset stm
      invoke GetSystemTime, esi; Get UTC
      mov   ax, stm.wHour
      inc   ax; GET UTC +1 i e CET
      mov   stm.wHour, ax 
invoke GetDateFormat, 1031, DATE_LONGDATE, addr stm, 0, addr dtbuf, 260
      lea   esi, offset dtbuf
      add   esi , eax  ; eax is len of format
      mov   byte ptr [ esi - 1 ] , " "
      pushad
      mov     eax,esp
      INVOKE  GetTimeFormat,1031,TIME_FORCE24HOURFORMAT,addr stm,NULL, esi,32
      add     esp,32
pop esi
invoke MessageBox, NULL, addr dtbuf, addr AppName, MB_OK
exit
      ret
start endp
    end start


We have now got GMT + 1 which is CET i e time in Berlin, Germany,

Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on March 04, 2013, 02:50:19 AM
      mov   ax, stm.wHour
      inc   ax; GET UTC +1 i e CET
      cmp   ax, 24
      jb    @F

      sub   ax, 24

@@:   mov   stm.wHour, ax 


or

      mov   ax, stm.wHour
      sub   ax, 23; GET UTC +1 i e CET
      jae   @F

      add   ax, 24

@@:   mov   stm.wHour, ax 
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on March 04, 2013, 02:59:58 AM

Hi DednDav:

I am sure sure there is an easier way.
But for now it goes.

Thanks for the ideas.
Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on March 04, 2013, 03:28:53 AM
of course - you could use the right Locale Identifier   :biggrin:
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on March 04, 2013, 03:34:08 AM

Hi DednDave:

Tossed first example in qeditor.
Compiled and tosed it to WinDbg.

Herge Says All Right!
Thanks DednDave.
Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on March 04, 2013, 03:38:02 AM
the second one is a little better, i think   :t
should be 2 bytes shorter
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on March 04, 2013, 03:42:25 AM
 Hi DednDave:

The LCID for germany is 1031 decimal that's why
we get nice German names.

A site to look up your LCID @ MicroSoft.


http://msdn.microsoft.com/en-us/library/ms912047(v=winembedded.10).aspx


Regards herge
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on March 04, 2013, 09:27:58 PM
 Hi Rubber Duck & UTC & GMT & Zulu Fans:

We got all that. To check your computer date and time the
folks in Ottawa, Ontario, CANADA have a site @ NRC.
I will let people @NRC explain NRC.


http://time5.nrc.ca/JavaClock/timeDisplayWE.shtml
(http://time5.nrc.ca/JavaClock/timeDisplayWE.shtml)

For America try NIST.

http://nist.time.gov/
(http://nist.time.gov/)
Pick Your Time Zone and Go.
Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on March 05, 2013, 01:07:17 AM
i used to visit CHU at 7.335 mHz (they broadcast on a couple other frequencies, as well)
a few years ago, they expanded the international broadcast band in ITU regions 1 and 3
CHU experienced some interference, so they moved to 7.85 mHz or something like that

here in the US, we have WWV (and WWVL, WWVB)
they broadcast at several frequencies, most notably 2.5, 5, 10, 15, 20 mHz
WWVL is at 20 kHz and WWVB is at 60 kHz

you can see what CHU sounds like, here...
http://en.wikipedia.org/wiki/CHU_%28radio_station%29#Time_signal_format (http://en.wikipedia.org/wiki/CHU_%28radio_station%29#Time_signal_format)
Title: Re: powershell and utc time aka greenwich london uk
Post by: herge on March 05, 2013, 05:56:51 PM

Hi DednDave:

We are going to the dogs.
Breaker one nine oh the good
old CB radios before portable telephones.
There use to be size of a lunch box. Now
about the size of a pack of fags(smokes, cigarettes).
Title: Re: powershell and utc time aka greenwich london uk
Post by: dedndave on March 05, 2013, 06:12:26 PM
heathkit used to make one we called the "lunchbox"   :P
they made them for 3 different ham bands and one for cb, too
back then, probably the cheapest way to get on the air

(http://www.radio-mart.net/images/P/IMG_9144.jpg)