What is the 'Type' of DateCreated attribute of file object?
I want to convert the 'DateCreated' value of a file into YYMMDD format. can anyone help which 'type' is this DateCreated object is? The MSDN says "Returns the date and time that the specified file or folder 开发者_运维技巧was created. Read-only."
I have the following code
var fso = new ActiveXObject("Scripting.FileSystemObject"); file = fso.GetFile("c:\abc\abc.txt"); var dt = file.DateCreated();
==> The value of dt will be shown as 2/10/2011 7:18:18 AM. But I need in YYMMDD format. I tried using substring function like
var s = dt.substring(0, dt.indexOf("")); but this is throwing 'object expected' error.
tried converting dt into string as dt.toString() but again the 'object expected' error.
can anyone help how do I convert into YYMMDD format?
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.GetFile("c:\abc\abc.txt");
var dt = new Date(file.DateCreated);
Try out the example on http://msdn.microsoft.com/en-us/library/ke6a7czx(v=vs.85).aspx to get the datetime. Then use split() more as one (because I cannot deal with regular expressions^^).
- Seperate the date and the timestamp width '.split()'
- Use the first array item and seperate the rest of the string, also with '.split()' use "\/" to mask the slash.
- Reorder the array fields for your own by concating to a string.
Ok it seems yery complicated, but it works.
I have just spent the past 6 hours dealing with this problem in javascript, so I thought I'd add my 2 cents:
I have been using Scripting.FileSystemObject to browse a file system and return a dateCreated. Am then passing that value as a param to a function that converts the date to another format.
within the helper function, I am using javascript date method such as getFullYear() to construct the new date from the param.
I Have constantly been getting "Object Expected". Turns out that the type returned by dateCreated is not the same as a javascript Date object.
For instance, if I apply the typeOf method to the DateCreated object I get "date". However, when I get the typeOf a javascript date I get "Date" (notice the capitalisation).
精彩评论