Ask a Question

How to convert time value in Milliseconds?

SOLVED
sshah1
Contributor

How to convert time value in Milliseconds?

Hi,

I have time value as string like this - 0000:00:05.016

Is it possible with TestComplete to --

1) Convert above string to time

2) Get total time as Milliseconds - 5016 ms

 

aqConvert["StrToTime"]("0000:00:05.016"); - does not work

 

Thanks,

Samixa

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
NisHera
Valued Contributor

Re: How to convert time value in Milliseconds?

If you are using jScript you can create a date using

var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);

so you can create date and manupulate as you like eg

var d = new Date(2016,00,28,16,45,19,50)
Log.Message(d)
Log.Message(d.getMilliseconds()+d.getSeconds()*1000);

for more http://www.w3schools.com/jsref/jsref_obj_date.asp

View solution in original post

sshah1
Contributor

Re: How to convert time value in Milliseconds?

Thanks for your response. Yes, it works.

View solution in original post

6 REPLIES 6
NisHera
Valued Contributor

Re: How to convert time value in Milliseconds?

If you are using jScript you can create a date using

var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);

so you can create date and manupulate as you like eg

var d = new Date(2016,00,28,16,45,19,50)
Log.Message(d)
Log.Message(d.getMilliseconds()+d.getSeconds()*1000);

for more http://www.w3schools.com/jsref/jsref_obj_date.asp

View solution in original post

sshah1
Contributor

Re: How to convert time value in Milliseconds?

Thanks for your response. Yes, it works.

View solution in original post

vinaypaluparthi
Occasional Visitor

Re: How to convert time value in Milliseconds?

Similarly in C# scripting??


NisHera
Valued Contributor

Re: How to convert time value in Milliseconds?

C# is not my expertise.... 

Hope below link or links attached to in would help https://docs.microsoft.com/en-us/dotnet/standard/base-types/how-to-display-milliseconds-in-date-and-... 

tristaanogre
Community Hero

Re: How to convert time value in Milliseconds?

As a suggestion, rather than using the native aspects of the language, considering using the aqDateTime, aqConvert, etc., objects.  Yes, doing a direct DateToStr won't work but aqDateTime allows for a number of ways of manipulating dates and times to customize your output.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
AlexKaras
Community Hero

Re: How to convert time value in Milliseconds?

Hi,

 

> Similarly in C# scripting??

C#Script in TestComplete uses the same JScript engine and actually is the same JScript with the syntax adopted for C# compiler. (This is not relevant now because the feature was created for Connected applications that are deprecated now.)

Long story short: C#, C++ and JScript syntax can be mixed within the same project.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
cancel
Showing results for 
Search instead for 
Did you mean: