openlang

Getting the present time as a seconds timestamp?

In Dyalog APL, the function ⎕TS provides today's current year, month, day, hours, minutes, seconds and so on, but can I obtain a timestamp counting seconds since, say, 1970-01-01 (a Unix timestamp)?

The conversation continues 2

Follow the reasoning
  1. Permalink

    With days, available at https://dfns.dyalog.com/n_days.htm

          )copy dfns days
    C:\Program Files\Dyalog\Dyalog APL-64 17.1 Unicode\ws\dfns.dws saved Thu Aug 22 18:35:12 2019
          86400×(days ⎕TS)-(days 1970 1 1)
    1570618042

    Another option is the over operator ⍥, arriving with Dyalog version 18.0

          )copy dfns days
    C:\Program Files\Dyalog\Dyalog APL-64 17.1 Unicode\ws\dfns.dws saved Thu Aug 22 18:35:12 2019
          over←{(⍺⍺ ⍺)⍵⍵ ⍺⍺ ⍵} ⍝ over operator definition
          86400×⎕TS days over - 1970 1 1
    1570618349
  2. Permalink

    Dyalog introduced ⎕DT (https://help.dyalog.com/latest/Content/Language/System%20Functions/dt.htm) in 18.0 to translate between various representations of dates and times. Format 20 represents UNIX timestamps, giving this expression for obtaining one now:

          20 ⎕DT ⊂⎕TS
    1659344012

    In fact, passing a single character on the right (a military timezone code) makes it assume the present time. However, that conversion treats its input date/time as UTC already, so obtaining an accurate result requires explicitly choosing UTC with uppercase "Z" (letter case matters for these zone codes):

          20 ⎕DT 'Z'
    1659358612

Other sides of the same question

  1. Swift - Making integers positive

    can an integer be converted to its absolute value? for instance I tried UInt() already, thinking it would turn the Int into a…

    Replies 4Latest activity swift
  2. Trouble drawing a correlation chart

    Hi folks, Could somebody explane why the Performance Analytics package's chart.Correlation function fails on the iris data, i…

    Replies 3Latest activity r
  3. How R handles repeated arithmetic signs

    I mistakenly put an extra + into my R code and found that it raised no complaint whatsoever. Actually, after trying a few mor…

    Replies 2Latest activity r