CRS Script Workaround for issue

William Bell
Vice President, Solutions and Products

I came across an issue working on a script enhancement for a customer where  I needed to  compare two time/date variables and evaluate the seconds that have expired between them.  The CRS development guide says that using the “.ms” method on a time variable would return epoch time but that is not so, or at least not the case with version 4.0.


CRS has Date variables and Time variables.  Date variables support multiple formats but will capture time values as well as MM/DD/YY values.  Time variables will get AM|PM values.  According to the CRS developer guide, if you have a date variable and use the “.ms” method you will get the number of milliseconds since January 1, 1970, 00:00:00 GMT (aka Unix epoch or epoch time).

Unfortunately, the developer guide is either incorrect or I am completely misunderstanding the document.  Whichever is the case, the syntax (and I tried multiple methods) isn’t getting me what it is supposed to.  Instead, I get the actual milliseconds for a specific instance in time. 
To work around this issue you have to execute a couple of conversions and assign the value to a variable of type long. This is done as follows:

Set lngEnterQ = Date.parse(D[now].toGMTString())

Basically, this will return the milliseconds that have expired since Jan 1, 1970 00:00:00 GMT.  It took some reading of the Java API to put that together.  The CRS developer guide does say you can do the .parse() and .toGMTString() functions but doesn’t explain them at all.  The .toGMTString() is pretty intuitive but the .parse() was not what I thought it was.

Here’s to Google and Sun’s Java documentation library.

2 responses to “CRS Script Workaround for issue

  1. should return the millisecond part of the Date object

    Also, a simpler way to get the epoch is to call ?.getTime() on your object.

    start_time = t[now].getTime()
    delay 5 seconds
    end_time = t[now].getTime()
    time_diff = end_time – start_time

    Of course this will not work in standard because you cannot use methods on objects in standard.

  2. Hi Bill,

    Thanks for blogging about this – I spent too long poring over the scanty documentation before finding. Kudos to Anthony to for posting his contribution.


Leave a Reply


Nick Kelly

Cybersecurity Engineer, Cisco

Nick has over 20 years of experience in Security Operations and Security Sales. He is an avid student of cybersecurity and regularly engages with the Infosec community at events like BSides, RVASec, Derbycon and more. The son of an FBI forensics director, Nick holds a B.S. in Criminal Justice and is one of Cisco’s Fire Jumper Elite members. When he’s not working, he writes cyberpunk and punches aliens on his Playstation.


Virgilio “BONG” dela Cruz Jr.

CCDP, CCNA V, CCNP, Cisco IPS Express Security for AM/EE
Field Solutions Architect, Tech Data

Virgilio “Bong” has sixteen years of professional experience in IT industry from academe, technical and customer support, pre-sales, post sales, project management, training and enablement. He has worked in Cisco Technical Assistance Center (TAC) as a member of the WAN and LAN Switching team. Bong now works for Tech Data as the Field Solutions Architect with a focus on Cisco Security and holds a few Cisco certifications including Fire Jumper Elite.


John Cavanaugh

CCIE #1066, CCDE #20070002, CCAr
Chief Technology Officer, Practice Lead Security Services, NetCraftsmen

John is our CTO and the practice lead for a talented team of consultants focused on designing and delivering scalable and secure infrastructure solutions to customers across multiple industry verticals and technologies. Previously he has held several positions including Executive Director/Chief Architect for Global Network Services at JPMorgan Chase. In that capacity, he led a team managing network architecture and services.  Prior to his role at JPMorgan Chase, John was a Distinguished Engineer at Cisco working across a number of verticals including Higher Education, Finance, Retail, Government, and Health Care.

He is an expert in working with groups to identify business needs, and align technology strategies to enable business strategies, building in agility and scalability to allow for future changes. John is experienced in the architecture and design of highly available, secure, network infrastructure and data centers, and has worked on projects worldwide. He has worked in both the business and regulatory environments for the design and deployment of complex IT infrastructures.