DateTime optionally containing microseconds

Hi all,

I'm sending DateTimes over soap to JADE agent system.

If I send over it is accepted fine.. and ends up as:


However, if I convert a Rails model field to datetime and send it over
its of class DateTime but loses the microseconds. Which my SOAP
server inconveniently requires to be present.


ends up as:


And is rejected.

I was able to get @seller.deadline.to_datetime to be accepted by
adding the microsecond portion of to it. But that seems
like an awful hack.

How do I ensure a given DateTime such as the one extracted from a
rails model is alays sent with the microsecond portion present over


        obj =
        obj.wiredump_dev = STDERR if $DEBUG

        time_periods =
        #time_periods[0] =
(@seller.deadline.to_datetime, @seller.openingOffer, @seller.alpha,
@seller.umin, @seller.deadline.to_datetime)
        time_periods[0] =
(@seller.deadline.to_datetime +,
@seller.openingOffer.to_f, @seller.alpha, @seller.umin,

        p time_periods[0]

        parameters = {
          :sellerID => @seller.sellerID,
          :maxPossPrice => @seller.openingOffer.to_f,
          :itemID => @seller.itemID,
          :deadline =>,
          :timePeriods => time_periods

        puts obj.clientGatewayCreateNewSeller(parameters)

If you can use a Time instance rather than a Date, you can get the format you want with something like this:

now =

Note that the .sub() takes off trailing 0's from the fractional time which may not be something that you want. Basically, you need to roll your own method (as you seem to have sensed). Seems like you can create a similar method for your DateTime instance using DateTime#sec_fraction like I've used Time#usec (microseconds; µs) along with DateTime#strftime.


Rob Biedenharn