Learning go lang. Might be a basic question.
I have an time.Time object and I wanted to get the epoch time for it. What I write to get that is :
fmt.Println(startTime.Unix)
where startTime is an object of time.Time. Now, I would have expected it to print some big number, something as, 1257894000, but what I get is : 0x814ff30.
Did not understand why? Would be happy to write more in case it is not clear.
Use time.Unix() function
fmt.Println(time.Now().Unix())
//1479454089
Related
I have a column of times in ALteryx like the following:
Time
=====
8:05 AM
8:07 AM
8:11 AM
8:12 AM
8:16 AM
...
They are currently stored as a String, but I want to convert them to the Time format. So far, I have tried using the LEFT and TRIM function to isolate the time itself as such:
Trim(Left([Time], 5)," ")
However, when I try to convert this to a Time datatype, I receive type conversion errors. How can I convert something like 8:46 AM from a String to a Time datatype in Alteryx?
I did some more digging and trying different things out, and I was able to figure it out. For the reference of others, here is what I did:
DateTimeParse([VisitTime] + " " + [PartofDay],"%I:%M %P")
Where [VisitTime] is the time expressed like 8:30 and [PartofDay] is AM or PM.
After this, I used a Select tile to change the datatype from String to Time without type conversion errors.
I have joined in a Data competition for students. They gave me timestamps of users' interaction. Is it useful?
Some of them are:
1615983880510
1615767552552
1615767577100
1616036788631
What you are looking at is a linux timestamp. It's actually a pretty interesting time representation. In short, it's just a number. And it represents the total number of seconds that have passed since January 1st 1970. A date known as "Unix Epoch Time".
Now, if you want to convert that into a readable date there are many ways to do it in basically every programing language. For example in python you might do something like this:
from datetime import datetime
def printdate(unix):
print(datetime.utcfromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
BUT! It seems like your dates might actually be in miliseconds. Meaning that you might actually want to divide your dates by 1000 before passing them trough the function. So...
def printdatems(unix):
return printdate(unix/1000)
And there you go!
printdatems(1615983880510) #2021-03-17 12:24:40
printdatems(1615767552552) #2021-03-15 00:19:12
printdatems(1615767577100) #2021-03-15 00:19:37
printdatems(1616036788631) #2021-03-18 03:06:28
That's the output for the example dates you provided.
Of course you can find much more information on Wikipedia:
https://en.wikipedia.org/wiki/Unix_time
It's an intresting read!
Using a standard VBScript Randomize statement (below) which works fine -- most of the time.
...RANDOMIZE (Cbyte(Left(Right(Time(),5),2)))
RANDOMIZE...
It took a bit, but in digging thru log files, I've noticed that it throws this 500 error:
Type mismatch: 'Cbyte'
when the users' languages are non-English.
I tried changing the Session.LCID (I'm using Classic ASP) in a test page but no effect.
Any suggestions for fixing or a work-around? Thank you...
It appears you're trying to randomise based on the seconds-within-the-minute value:
12:34:56 AM
|---|
56 AM (right(5))
||
56 (left(2))
Now I have no idea of the top of my head what Time() would return in a Spanish locale, but it may well be something like 12:34:56 de la mañana.
What I do know is that relying on a specific presentation format in a globalised world is a bad idea. In your case, it may involve trying to convert left(right("12:34:56 de la mañana",5),2), or "añ", into a numeric value, something it's not going to be happy with.
If you want a true root cause analysis, I'd suggest catching the conversion error and actually logging what Time() is presenting itself as when it errors.
If you just want to fix it, find a way to get the seconds that doesn't depend on locale, for example:
secs = Second(Time())
As an aside, I'm not sure why you think this is even needed. The documentation for the VBScript Randomise function states that, if an argument is not given, the value returned by the system timer is used as the new seed value. Hence it's already based on the current time.
I see requests to socket.io containing parameter t to be like LZywzeV, LZz5lk7 and similar.
All examples that i found so far used second- or millisecond-based UNIX timestamps.
Has anyone ever seen a timestamp format like this? (It is not base64-encoded).
I started looking a site that uses Socket.io today, and got the same problem, trying to look for the protocol definition was useless.
I figured this format is something called yeast
TBH, really don't know why people invent this sort of things instead of use
base64(timestamp.getBytes())
pseudocode instead.
A yeast decode algorithm in Python is as follow:
from datetime import datetime
a='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'
b={a[i]: i for i in range(len(a))}
c=0
for d in "LZywzeV":
c=c*64+b[d]
print(c)
print(datetime.fromtimestamp(c/1000))
The output of that code is:
1481712065055
2016-12-14 07:41:05
to #jeremoquai:
It is easy, is matter of invert the algorithm:
def yeast(d):
r=""
while d!=0:
r='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'[d&63]+r
d>>=6
return r
so, if you run
yeast(1481712065055)
it returns LZywzeV
I have parsed a date in json like below
DateTime.parse(parsed["LastTimeReportGenerated"])
Now I'm trying to do Time.now-DateTime.parse(parsed["LastTimeReportGenerated"])
Whitout success. Getting the error message
scheduler caught exception:
can't convert DateTime into an exact number
What is the correct syntax? Sorry for this simple question but could't find an obvious answer to this.
The --Method of the Time object only accepts another Time object or a number (seconds) to subtract. You are giving a DateTime object, which can be converted to a Time object:
Time.now-DateTime.parse(parsed["LastTimeReportGenerated"]).to_time