找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 18807|回复: 4

[问题求助] vbs如何获取执行js代码后的返回值(Unix时间戳)?

[复制链接]
发表于 2016-6-23 11:31:07 | 显示全部楼层 |阅读模式
本帖最后由 pcl_test 于 2016-6-24 13:22 编辑
  1. 'win7x64,强制在32位环境运行脚本
  2. Set oWS  = CreateObject("WScript.Shell")
  3. Set oFSO = CreateObject("Scripting.FileSystemObject")
  4. s = oWS.ExpandEnvironmentStrings("%windir%\SysWOW64\WScript.exe")
  5. If oFSO.FileExists(s) = True And LCase(WScript.FullName) <> LCase(s) Then
  6.     oWS.Run s & " """ & WScript.ScriptFullName & """"
  7.     WScript.Quit()
  8. End If

  9. Function timestamp()
  10.     Dim js:Set js = CreateObject("ScriptControl")
  11.     js.language = "JScript.encode"
  12.     'timestamp = js.EVAL("#@~^FAAAAA==c        +A,fmY+*R7CV!+60v#igYAAA==^#~@ ") '这个可以显示
  13.     timestamp = js.EVAL("msgbox (new Date()).valueOf();")
  14. End Function

  15. msgbox timestamp()
复制代码
msgbox在Java里不好执行啊

评分

参与人数 1PB -6 收起 理由
pcl_test -6 勿发笼统的标题

查看全部评分

发表于 2016-6-23 12:06:46 | 显示全部楼层
timestamp = js.EVAL("(new Date()).valueOf()")
另mshta也能较好解决两者的混编问题
 楼主| 发表于 2016-6-23 15:59:42 | 显示全部楼层
这个是读取的当前时间,再请问一下,怎么指定时间

"(new Date()).valueOf('2010-01-01)"
这样不行么

这是是把时间转换为13位数字时间戳
反过来转换的语句又是什么?

谢谢
 楼主| 发表于 2016-6-23 21:01:30 | 显示全部楼层
本地时间转为13数字时间戳
timestamp = js.Eval("new Date('2010/03/08 10:01:02').getTime();") '指定时间,必须是/
timestamp = js.Eval("new Date().getTime();")                      '当前时间

13数字时间戳转为本地时间
timestamp = js.EVAL("new Date(parseInt(1293072805000)).toLocaleString();")

10数字时间戳
http://demon.tw/programming/vbs-unix-time-stamp.html
DateDiff() 把时间转为时间戳
DateAdd()  把时间戳转为时间
发表于 2016-6-24 15:02:26 | 显示全部楼层
本帖最后由 pcl_test 于 2016-6-28 09:07 编辑
  1. Function ToUnixTime(dt, ms, n)
  2.     Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
  3.     Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
  4.     For Each objItem in colItems
  5.         TimeZone = objItem.CurrentTimeZone
  6.         If isNull(ms)=true Then
  7.             ms = left(split(objItem.LocalDateTime, ".")(1), 3)
  8.         End If
  9.     Next
  10.     ToUnixTime = DateDiff("s", "1970-1-1 0:0:0", dt) - TimeZone*60
  11.     If n=1 Then ToUnixTime = ToUnixTime *1000 + ms
  12. End Function
  13. 'msgbox ToUnixTime(CDate("2010/03/08 10:01:02"), 000, 1)
  14. msgbox ToUnixTime(now(), null, 1)  '0表示输出秒级Unix时间戳,1表示输出毫秒级
复制代码
  1. Function FromUnixTime(ts, n)
  2.     Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
  3.     Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
  4.     For Each objItem in colItems
  5.         TimeZone = objItem.CurrentTimeZone
  6.     Next
  7.     ms = ""
  8.     If n = 1 Then
  9.         'ms = "." & right(ts, 3)
  10.         ts = left(ts, len(ts) -3)
  11.     End If
  12.     FromUnixTime = DateAdd("s", ts + TimeZone*60, "1970-1-1 0:0:0") & ms
  13. End Function
  14. msgbox FromUnixTime(1293072805000, 1)  '0表示以秒级转换成时间,1表示以毫秒级转换
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 07:43 , Processed in 0.086153 second(s), 12 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表