get UTC (milliseconds) in max?

thispatcher's icon

Hi!

I want to get the unix time code in milliseconds.

I tried using the [shell] object. Since I am running mac osx, installed the coreutils so that i could get the utc in nanoseconds from terminal, but while "gdate +%s.%N" works in terminal, it does not work in shell object.

I've tried to do it in javascript, but:
//
var utc = new Dict("dict_UTC");
function bang()
{
var d = new Date();
utc.set("post_time", d);
}

causes max to crash.

I've also tried variations of

//
function bang()
{
var d = new Date();
outlet(0, d());
post(d);
}

but when I get the UTC, it won't change, only seems to output the utc from when max was loaded. I got this code from this thread https://cycling74.com/forums/unix-timestamp

But as I say, it will output a UTC only once, and even if I recompile the js in the js object, or even cut/paster the whole thing, it still outputs the same utc. right now it is outputting "1466604453888."

Any thoughts on how to do this, or perhaps an object that already exists? I'm working on a system where I need events to be tagged with UTC, so ideally I just send a bang and get the UTC at that instant.

Thanks very much!!

Michael

Source Audio's icon

ruby -e 'puts Time.now.to_f'

message to shell returns utc ok for me.
Max 6, OSX 10.6.8

Source Audio's icon
Max Patch
Copy patch and select New From Clipboard in Max.

here is provided patch, because pasted text above into reply field changed the ’ into ‘
making it unusable ...
I just happened to check if it workes for You and detected the error

thispatcher's icon

Thank you so much this good!

One issue is that I am unable to reformat the output from what appear to be a string to a number. So going from the shell to a 'fromsymbol' object, I'm getting the same error I described above. Any thoughts?

thispatcher's icon

Oh I see, it must be because max cannot handle that size of a number.. hmm. I'll look into it.

Source Audio's icon

Correct, max seams not to be able to handle that number / float.
Now depending in which form You need to store/ read the timstamp,
it could be enough to keep it as symbol, the way it gets reported by shell ?
Shell output to text object remains intact, as well to textedit, coll ...
Only when it gets treated as float it gets to it's limits