Using Javascript under WSH

Microsoft / Windows vista
September 29, 2009 at 10:12:18
Specs: Windows Vista Ultimate SP2, 3GB
I was just experimenting with the idea of using JavaScript with WSH as a quick-and-dirty way of writing prototype or small throwaway applications. The advantage is that, unlike batch files, JavaScript is a proper programming language, but, unlike Java or C, you can develop on any Windows PC, without needing to install the JDK or VS. And the advantage over VBScript is that, once you've developed in Javascript you can port it to Linux or any other platform with minor modifications by embedding it in an html file.

Now I've started playing around with it but got stuck.

WScript.echo("Hello, world") works fine.
WScript.echo("The time is" + now()) doesn't, though it does work on VBScript. What's the equivalent in JScript?

See More: Using Javascript under WSH

Report •

September 29, 2009 at 12:06:22
JScript does not have a "Now" function. You would have to implement your own using the Date() object. Here's a simplistic example:

var now = new Date();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();

if (minute < 10)
minute = "0" + minute;
var timeNow = hour + ":" + minute + ":" + second;

Report •

September 29, 2009 at 23:32:15

Report •

Related Solutions

Ask Question