Search code examples
vbscripttimezonewmijscript

How to get the file modified date of a file with respect to a particular time zone in Jscript?


I have a file which gets created/modified on a PST machine. But when I am accessing this file from an Indian standard time, the Modified date will be returned according to the current system time zone. (As explained here) Is there any way I can get this date with respect to the time zone provided

var WshShell = Sys.OleObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");           
var objFile = fso.GetFile("c:\\abc.txt");
var date = objFile.DateLastModified + "";

Solution

  • Yes, you do this with the DateDiff function in VBS:

    http://www.devguru.com/technologies/vbscript/quickref/datediff.html

    DevGuru Info

    DateDiff(Interval, Date1, Date2, FirstDayofWeek, FirstWeekofYear)
    
    The DateDiff function calculates the amount of time between two different dates.
    There are three mandatory arguments.
    
    Interval
    
    The Interval argument defines the the type of time interval you wish to use to
    calculate the time difference.
    
    Only the following settings can be used. You must place the setting inside a
    pair of double quotes.   
    
    | SETTING | DESCRIPTION  |
    |:--------|:-------------|
    | YYYY    | Year         |
    | Q       | Quarter      |
    | M       | Month        |
    | Y       | Day Of Year  |
    | D       | Day          |
    | W       | WeekDay      |
    | WW      | Week Of Year |
    | H       | Hour         |
    | N       | Minute       |
    | S       | Second       |
    

    In javascript you can do it like this:

    How to calculate date difference in javascript