Changing the date format to Greenwich Mean Time (GMT) using Classic ASP

Can anyone help me convert the date to GMT format? I would really appreciate any assistance.

Update:

I came across this code snippet:

<% response.write currentUTC() %>

<script language=jscript runat=server>
    function currentUTC(){
    var d, s;
    d = new Date();
    s = "Server current UTC time is: ";
    s += d.toUTCString('!%a, %d %b %Y %H:%M:%S GMT');
    return(s);
  }
</script>

The output is: Server current UTC time is: Fri, 15 Jan 2016 07:42:13 UTC

However, I need it in the format YYYYMMDDHHMMSS.

Any ideas?

Update:

I attempted to use the following function:

GetServerGMT=Year(Now())&Month(Now())&Day(Now())&Hour(Now())&Minute(Now())&Second(Now())&WeekDay(Now()) 

It returns: 20161172035121

But that doesn't seem to be a valid timestamp.

Answer №1

Expanding on Lankymart's reference. When working with ASP Classic, there are numerous time and date options available, but it often necessitates creating a distinct function or subroutine for each unique case.

In my experience, the GMT value in my HTTP Only cookie differs from that in my GMT RSS Feed layout.

For instance: strGMTDateRFC22 = CookieServerUTC("d",1,5,"GMT")

'# following formating RFC22 for your GMT Cookie time. 
    strGMTDateRFC22 = CookieServerUTC("d","&strCookieExpires&",5,"GMT")  ' 1 Day set in char enc dec page
    Response.AddHeader "Set-Cookie", strCookieName & "=" & strCookieKey & "=" & strCookieValue & "; expires=" & strGMTDateRFC22 & "; domain="& strCookieDomain &"; path=/; HTTPOnly"

The first of two functions:

Function CookieServerUTC(strD,strT,strOSet,strZ)
Dim strTG,strCookieD
'snipped unwanted code
        strTG = DateAdd("h", strOSet,Now())
        strCookieD = DateAdd(strD,strT,CDate(strTG))
     CookieServerUTC =  fncFmtDate(strCookieD, "%a, %d %b %Y %H:%N:%S "&strZ&"")
    End Function

Another scenario where setting up Server UTC is necessary - accommodating parameters for strH = "h", strT = "5" (strT Time Offset +/-), and strZ representing GMT (Timezone).

Function GetServerUTC(strH,strT,strZ)

 GetServerUTC = fncFmtDate(DateAdd(strH,strT,Now()), "%a, %d %b %Y %H:%N:%S "&strZ&"")
    
End Function

Additionally, here is the script released in 2001 during the prime days of ASP Classic. Shared by 4guysfromrolla.com, it has likely aided countless Time Date format enthusiasts.

Access the link below which contains the customizable date formatting routine developed by Ken Schaefer: Customizable Date Formatting Routine by Ken Schaefer

Function fncFmtDate( _
        byVal strDate, _
        byRef strFormat _
       )
     ' Accepts strDate as a valid date/time,
     ' strFormat as the output template.
     ' The function finds each item in the
     ' template and replaces it with the
     ' relevant information extracted from strDate
     
     ... (omitted for brevity) ...
     
    End Function ' fncFmtDate

With plenty of solutions at hand, select the date time formatting method that aligns best with your projects and advance from there.

... (remaining content left untouched) ...

Answer №2

The content within the Date() function dictates the outcome. Understanding the Time Zone of the server is crucial in Classic ASP, as it retrieves the date from the Regional System Settings of the hosting Web Server.

To adjust for different time zones, utilize the DateAdd() function by adding or subtracting hours based on the necessary offset.

<%
Dim offset
'Offset example: PST to GMT
offset = -8
Response.Write DateAdd("h", offset, Date())
%>

However, the output remains a raw date string displayed according to default format settings dependent on the Server's regional configuration.

For tailored date formats, visit Format current date and time.

Referencing this comment, rearrange date components for a custom format like YYYYMMDDHHMMSS:

Dim dt
dt = yy & mm & dd & hh & nn & ss
Response.Write dt

Calculate date values using Now(); substitute with:

dtsnow = DateAdd("h", offset, Date())

Prior to offering assistance outright, consider attempting the modifications independently following the guidelines from the provided reference.

Dim dd, mm, yy, hh, nn, ss
Dim datevalue, timevalue, dtsnow, dtsvalue

'Store DateTimeStamp once without offset.
dtsnow = Now()

'Capture individual date components
dd = Right("00" & Day(dtsnow), 2)
mm = Right("00" & Month(dtsnow), 2)
yy = Year(dtsnow)
hh = Right("00" & Hour(dtsnow), 2)
nn = Right("00" & Minute(dtsnow), 2)
ss = Right("00" & Second(dtsnow), 2)

'Construct yyyyMMdd date string
datevalue = yy & mm & dd
'Formulate HHmmss time string
timevalue = hh & nn & ss
'Merge both to acquire timestamp yyyymmddhhmmss
dtsvalue = datevalue & timevalue

'Display on screen
Call Response.Write(dtsvalue)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using the Jquery :not selector in combination with a wildcard

I've been working on a simple onclick function to hide divs based on their loop number, but I'm struggling with getting the not selector to work. In simpler terms, I want all divs that have a class starting with "title" except for the current on ...

Combine multiple arrays in JavaScript into a single array

Here is the array I am working with: array = ['bla', ['ble', 'bli'], 'blo', ['blu']] I need to transform it into this format: array = ['bla', 'ble', 'bli', 'blo', &a ...

How can I troubleshoot the 'mdDialog console error' that says 'cannot read property element of null'?

Two of my templates are named Left_template_view_html and center_template_view_html When I click on a md-button in the Left_template_view_html I am attempting to display an mdDialog on the document.body What should I pass into the parent parameter: angu ...

Solving yarn conflicts when managing multiple versions of a package

My software application contains a vulnerability related to a package that has different versions available (1.x, 2.x, 3.x). Since many other packages rely on this particular one as a dependency, updating each one individually is not a viable solution at t ...

Collecting and storing all <a> tags within a variable, excluding those with specific ID names

I am facing a situation where I have a variable named notincluded: var notincluded = “one,two,three” Unfortunately, I am unable to modify the format of this variable. My challenge now is how can I convert “one,two,three” into a format that can be ...

Tips on incorporating a condition within an array of objects using JavaScript

I am working with a nested array of objects and need to add conditions and remove objects based on certain criteria. const Items = [ { A: 'title', B: [], C: [ { item1: item1}, { item2: item2 }, { ...

The debate: Switching off Next.js SSG - Harness or Constant?

Currently experimenting with different methods to disable NextJS SSG. The following custom hook implementation is functional: import { useState, useEffect } from "react"; const useClientCheck = () => { const [isClient, isClient ...

Sharing Controller variable with JavaScript file on ASP.NET MVC platform

Being new to ASP MVC, I have successfully retrieved data from a database. Now, I am looking for a way to pass that variable to a JavaScript file. This is my controller code: using (issue_management_systemEntities db = new issue_management_systemEntities ...

I encountered a 'Reference Error: button is not defined' issue

Exploring the concept of 'Closure' and experimenting with this sample code. Testing it out in Visual Studio Code. for (let [idx,btn] of buttons.entries()) { btn.addEventListener( "click", function onClick(){ con ...

Obtain a file from React Native in order to upload an image, just like using the `<input type="file" onChange={this.fileChangedHandler}>` in web development

After experimenting with different methods, I attempted to achieve the desired result by: var photo = { uri: uriFromCameraRoll, type: 'image/jpeg', name: 'photo.jpg', }; and integrating axios var body = new FormData( ...

I am interested in organizing a three-dimensional array using JavaScript

Just the other day, I posted a question on PHP, but now I need similar help for JavaScript. Here is my array : var inboxMessages = { 105775: { 0: { 'id': 85, 'thread_id': 105775, ' ...

Guide on incorporating a PNG logo into the Tailwind CSS navbar using Next.js

I am attempting to replace the SVG logo in this code with a PNG logo, but every time I try to add an img element, nothing appears on the page. The new image/logo should be approximately the same size as the original SVG logo. https://i.sstatic.net/3Xuyj.j ...

Enable the use of empty spaces in ag-grid filter bars

I'm experiencing an issue with the ag grid filter. It seems to be disregarding white spaces. Is there a way to configure the grid to recognize blank spaces in the filter? Any suggestions for resolving this issue? Where can I find the option to accept ...

Submitting a Form with Multiple Pages

I'm encountering a challenge that I'm struggling to work through. Initially, we had a professional build our website, but since parting ways with the company, I've taken over site management. While I can handle basic tasks, I lack the expert ...

Issue with React Audio Recorder causing useState hook to return null for recorded audio

I'm currently working on a registration form using React that allows users to enter their username and record audio with the react-audio-voice-recorder library. I've implemented the useState hook to handle the state of the recorded audio blob, bu ...

Verify if the input text field meets the minimum value requirement upon submission

I have a basic HTML form on my website... After collecting the user input, I convert it into JSON data (intending to send it elsewhere later on. Currently, just using console.log for testing). Once the user fills out the form and clicks submit, I want to ...

Adjust the height of a Vue.js div element

I am currently working with Vue.js and I need to adjust the height of one div based on the height of another div using pure JavaScript. The issue I am encountering is that I am unable to set the height using plain JavaScript, however it works fine with jQu ...

Java Script error persisted in db.system.js.save within MongoDB encountered but remains unresolved

Hello all, I am fairly new to the world of mongoDB and I need some help with performing a search using js stored in mongoDB. Below you will find the javascript code that is stored in my mongoDB database. When attempting the query below: db.eval("dc(cough ...

JavaScript-powered horizontal sliderFeel free to use this unique text

I'm new to JS and trying to create a horizontal slider. Here's the current JS code I have: var slideIndex = 0; slider(); function slider() { var i; var x = document.getElementsByClassName("part"); for (i = 0; i < x.length; i++) { x[i].styl ...

Tips for creating a unique identifier for each component when initializing the useState() function

I need assistance with creating 30 empty Taskcard components in the state. The issue is that each Taskcard is assigned the same id. How can I resolve this problem? import React from 'react' import { useEffect, useState } from 'react' ...