Brian Candler wrote:
> Alfonso Caponi wrote:
>> how can I use unpack a hex system date like this 2007-5-24,10:24:33.7 ?
>> 
>> I'm trying with systemdate.unpack("H2H2-H2-H2,H2:H2:H2.H2") but it
>> doesn't works :(
> 
> Please write your question more clearly, showing  few lines of 
> standalone ruby that demonstrate what you are trying to do. We don't 
> have your "systemdate" method so we don't know what it returns.
> 
> Are you saying that the source string looks like this?
> 
>>> systemdate = "2007-5-24,10:24:33.7"
> 
> If so, this is clearly not hex, this is a series of decimal values. So 
> if that's not what you're trying to convert, please give an example of 
> something that you are.
> 
> Then, how do you want to "unpack" it? For example, do you want to split 
> it into an array of numberics, e.g.
> 
> [2007,5,24,10,24,33.7]
> 
> - or something else?
> 
> If I have guessed what you want, here is a starting point:
> 
>>> systemdate.split(/[-,:]/)
> => ["2007", "5", "24", "10", "24", "33.7"]

Yes, sorry me.

I would convert the result of a SNMP query (1.3.6.1.2.1.25.1.2.0).
It's a hex string and It could be in these formats (for linux and 
windows):

2009-12-28,11:37:25.0,+1:0
2009-12-28,11:53:34.0

With systemDate = systemDate.unpack("H*") I've 07d90c1c0b2a28002b0100,
where 07d9 is 2009 in decimal, 0c is 12, 1c is 28 and so on.. :(

Thank you very much




-- 
Posted via http://www.ruby-forum.com/.