Current Time Milliseconds Long Integer

Current Time Milliseconds Long Integer

  

Hi,

I'm working with REST service and I put a date in my OutSystems application. My problem is that I put the date, but this number is a long int, I want to show it about "Date" date type. How can I do the convert between this data types?

Thanks, 

Jordi.

Hi Jordi, could you be more specific in the description of your problem? I don't really understand the problem you are stating. Are you exposing a REST service or are you consuming a REST service? Is the attribute with the Date data type present in an input or output structure? What do you expect from the conversion between a long int and a date?

In the platform, there is no built-in function to perform this conversion. Nonetheless, you could build your own as long as you know how the conversion should be done, from a functional perspective.

It probably helps if you provide an example of the behaviour you would like to see.

Hi Pedro,

My intention is to convert a Long Int into a Date, but there is no function for it. Can I create one to do it? If yes, how do I create that function?

Thanks for your reply,

Jordi

Hi Jordi,

assuming you are using OutSystems on .NET, you can create an extension with one single action. The input is a long integer (TimeInMilliseconds) and the output is a date time (DateTime). Then the code you need to write in visual studio is quite simple, namely: ssDateTime = new DateTime(ssTimeInMilliseconds * 10000).

Then you can use the DateTimeToDate built-in function to convert the date time into a date. 

Pedro Rodrigues wrote:

Hi Jordi,

assuming you are using OutSystems on .NET, you can create an extension with one single action. The input is a long integer (TimeInMilliseconds) and the output is a date time (DateTime). Then the code you need to write in visual studio is quite simple, namely: ssDateTime = new DateTime(ssTimeInMilliseconds * 10000).

Then you can use the DateTimeToDate built-in function to convert the date time into a date. 

Hi Pedro,

I'm using OutSystems with Service Studio, and I'm trying to do this conversion in a component of my application. My question is where i can create a new function, i'm rookie in this platform, sorry about the questions.

Thanks,

Jordi.


Hi Jordi, you need to create an extension with Integration Studio. You also need to have visual studio installed in your machine and configured within integration studio.


How to install visual studio on your machine?

https://www.youtube.com/watch?v=R6dZJ-FEypk

How to configure visual studio in integration studio? https://www.outsystems.com/forums/discussion/9519/how-to-configure-integration-studio-to-work-with-net-and-java-j2ee-extensions/


Check the links available on the following discussion to see how you can create an extension: https://www.outsystems.com/forums/discussion/15119/how-to-create-an-extension/


Finally, you need to take into account on whether the current time in milliseconds that you want to convert is calculated from 01-01-1900 00:00:00 UTC (Unix Epoch time). This is probably the case, but just to make sure. If this is the case, than your code becomes the following:

DateTime firstDateDime = new DateTime(1970,1,1);

long elapsedTicks = firstDateTime.Ticks + ssTimeInMilliseconds * 10000;

ssDateTime = new DateTime(elapsedTicks);


Good luck!

Solution

If the Long Integer is in milliseconds, I would prefer to do the conversion in Service Studio, rather than creating an Extension. To do so, divide the Long Integer by 86400000 (the number of milliseconds on a single day) and use the results in an AddDays: AddDays(NewDate(1970, 1, 1), MilliSeconds / 86400000). That's a lot easier than creating an extension :).

Solution

That is indeed an easier solution :)

Kilian Hekhuis wrote:

If the Long Integer is in milliseconds, I would prefer to do the conversion in Service Studio, rather than creating an Extension. To do so, divide the Long Integer by 86400000 (the number of milliseconds on a single day) and use the results in an AddDays: AddDays(NewDate(1970, 1, 1), MilliSeconds / 86400000). That's a lot easier than creating an extension :).


Hi Kilian,

Thank you very much, this is the solution that I'm trying to find.

Thanks, 

Jordi.