Computing.Net > Forums > Programming > Using Javascript under WSH

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Using Javascript under WSH

Reply to Message Icon

Name: klint
Date: September 29, 2009 at 10:12:18 Pacific
OS: Windows Vista Ultimate SP2
CPU/Ram: 3GB
Product: Microsoft / Windows vista
Subcategory: General
Tags: javascript
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: l0ngsh0t
Date: September 29, 2009 at 12:06:22 Pacific
Reply:

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;


1

Response Number 2
Name: klint
Date: September 29, 2009 at 23:32:15 Pacific
Reply:

Thanks!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Java: sorting arraylist, ... Perl : converting .elf (b...


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Using Javascript under WSH

request params using javascript www.computing.net/answers/programming/request-params-using-javascript/8901.html

Creating a DSN using VBScript www.computing.net/answers/programming/creating-a-dsn-using-vbscript/1902.html

JAVAscript redirection www.computing.net/answers/programming/javascript-redirection/14338.html