Discord
Login
Community
DARK THEME

Local time.

My time is CET +2 hours GMT.

When I run the program and ask for the time, I always get information that the current time is 2 hours shifted.

When the watch shows 18:00. The program running in MicroStudio says it is 4:00 PM.

I am using MicrosoftStudio offline version, Firefox 102, the operating system is Windows 8.1.

This is the code I use for time testing.

MicroScript is missing a variable to query for time zone offset.

TimeTest = class
  constructor = function()
    this.h = 0
    this.m = 0
    this.s = 0
  end
  now = function()
    local time = system.time()  % 86400000
    // 24 h * 60 m * 60 s * 1000
    local ms = time % 1000
    time = ( time - ms ) / 1000
    s = time % 60 
    time = ( time - s ) / 60
    m = time % 60 
    time = ( time - m ) / 60
    h = time 
  end
  nowH = function()
    return h
  end
  nowM = function()
    return m
  end
  nowS = function()
    return s
  end
end

init = function()
  timeTest = new TimeTest()
  timeTest.now()
  lastSec = timeTest.nowS()
end

update = function()
  timeTest.now()
  if timeTest.nowS() != lastSec then 
    lastSec = timeTest.nowS()
    print( 'Time h: ' + timeTest.nowH()+ '  m: '+ timeTest.nowM() + ' s: ' + timeTest.nowS())
  end
end

draw = function()
end

If you need a time for a specific zone you could just add (or subtract) the necessary number of milliseconds to your line like this:

local time = (system.time() + 2 * 60 * 60 *1000) % 86400000

(+ 2 hours)

or have a user selectable time zone.

I wouldn't say it's a 'bug' but might be convenient if there was a call like system.time(2) or system.time(-6)

Quite an hack, but you can use javascript inside microScript to achive some functionality still missing:

dateTime = function()

    system.javascript("""
    var today = new Date();
    var date = today.getFullYear()+'_'+(today.getMonth()+1)+'_'+today.getDate();
    var time = today.getHours() + '_' + today.getMinutes() + '_' + today.getSeconds();
    return date + '_' + time
    """)
  
end

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community