Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
773 views
in Technique[技术] by (71.8m points)

utc - Current Universal time in classic asp

How can I get the current time as Universal time in classic asp. I know how to get in C# and I am getting the universal time in c# with following line ((DateTime.Now).ToUniversalTime()).ToString("s") and this code gives me time like this 2012-07-09T10:29:49

But I want to know the equivalent in classic asp. Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As Ian pointed out you can generate a UTC time via Javascript.

You specified "ASP Classic" which of course includes Javascript as a language, so there's one answer for you: Call (new Date()).toUTCString().

If by chance you prefer to code your pages in mostly VBScript, you can mix in just a little Javascript to get it done. You don't need to resort to Server.Execute or Sessions to make that happen.

This works for me:

<%@ language="VBScript" %>
<script language='Javascript' runat='server'>
  function jsGetUTCTime() {
    var d = new Date();
    return d.toUTCString();
  }
</script>
<script language='VBScript' runat='server'>
Function getUTCTime()
    ' Use JScript to get the current GMT time stamp
    getUTCTime = jsGetUTCTime()
End Function
</script>
<!DOCTYPE html>
<html>
  <head>
    <title>Mix</title>
  </head>
  <body>
   <h2>The time is:</h2>
   <%= getUTCTime() %>
  </body>
</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...