I want to perform Type Conversion of Date Type Value

0 votes

Here is what I need to do:

I need to convert date and time in hex code for writing it on IOT device. Here is my code

private String getDateTimeToHexa() { 

Calendar mCalendar = Calendar.getInstance();
TimeZone gmtTime =  TimeZone.getTimeZone(TimeZone.getDefault().getDisplayName());

    mCalendar.setTimeZone(gmtTime);
    final Date date = mCalendar.getTime();
    return Long.toHexString(date.getTime());
}

It is returning 11 digits hex code I need 8 digits, just like date and time in hex is 47C7EDE0 for this date 12:34:56 29/Feb/2008

Aug 3, 2018 in IoT (Internet of Things) by Matt
• 2,260 points

edited Aug 20, 2018 by Matt 22 views

1 answer to this question.

0 votes

Instead of returning

return Long.toHexString(date.getTime());

Return following

return Long.toHexString(date.getTime()/1000);

As correctly pointed out by @shmosel that date.getTime() return time in a millisecond and if you want 8 digit Hex format then it needs to be converted in the second format.

The return type of Date can be found here

answered Aug 3, 2018 by anonymous2
• 4,260 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer
0 votes
1 answer

Azure IoT Hub : How to set Epoch Value of an Azure Function?

Try using Azure IoT Hub consumer groups, if ...READ MORE

answered Feb 21 in IoT (Internet of Things) by Shubham
• 13,210 points
60 views
0 votes
1 answer

How to use the data I receive from Azure IoT Hub?

The payload you receive will be a ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by DataKing99
• 8,100 points
62 views
0 votes
1 answer

How to tackle Security Loopholes of IoT Solutions ?

This is pretty off-topic, but I'll supply ...READ MORE

answered Aug 23, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
36 views
0 votes
1 answer
0 votes
1 answer

AWS IoT login from android MQTT client using IAM is not working

Seeing your comments and questions. I had ...READ MORE

answered Jul 24, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
254 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer