How can I write a correct serial date time in HDF5 file in Java?

I wrote a HDF5 file by IHDF5Writer based on http://svnsis.ethz.ch/doc/openbis/S176.0/ch/systemsx/cisd/hdf5/IHDF5Writer.html in Java.
I converted the java.Util.Date to serial date days since 1970-01-01 by

/**
* Converts a java.util.Date into a MATLAB Serial Date Number in the local timezone. MATLAB Serial Date Number are
* doubles counting the number of days since January 0 0000. The time of day is represented in fractions of a whole
* day.
*
* @param date the date to convert
* @return the date as MATLAB Serial Date Number
*/
public static double ToMATLABDate(Date date) {
// Converts a java.util.Date into a MATLAB Serial Date Number taking into account timezones and DST.
Calendar cal = new GregorianCalendar();
cal.setTime(date);
double SerialDateNumber = (date.getTime() + cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 1000.0 / 3600.0 / 24.0 ;
return SerialDateNumber;
}

I wrote the time to HDF5 file :

writer.writeDoubleArray(“time”, time);
writer.string().setAttr(“time”, “units”, “days since 1970-01-01”);

I checked the resulted test.h5 file in Panoply and in NCAR Command Langue but they are not able to convert the serial date to date even though I set the attribute.
Can someone inform me how I can write serial date correctly in HDF5 file?

Hi All, Please ignor this question. I checked the created hdf5 file in Climate Data Operator and it converted the serial date to date correctly. Moreover NCARG NCL cd_calendar function can also give back correct date.