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 4, 2018 in IoT (Internet of Things) by Matt
• 2,270 points

edited Aug 20, 2018 by Matt 777 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 4, 2018 by anonymous2
• 4,240 points

Related Questions In IoT (Internet of Things)

+1 vote
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, 2019 in IoT (Internet of Things) by Shubham
• 13,490 points
1,275 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,250 points
1,808 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,240 points
878 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,240 points
2,347 views
0 votes
1 answer
0 votes
1 answer

I want to restrict the opening of Browser on URL Click

You can call it as a web ...READ MORE

answered Aug 7, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
5,544 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP