Skip to main content
Known Participant
October 17, 2024
Answered

HOW TO SET A JAVA FILE EXPIRY DATE ?

  • October 17, 2024
  • 3 replies
  • 4452 views

 

I already have a java script, I want to add expiry date in it, how to do it. Please give me the code. and how to do it

 

This topic has been closed for replies.
Correct answer Stephen Marsh
var today = new Date();
alert(today);

How to add this code??

 


quote
var today = new Date();
alert(today);

How to add this code??

 


By @MJ ST

 

You would research how to work with dates with JavaScript, among a few other things.

 

Here is a working demo for you. It is not guaranteed to be fit for purpose or covered by warranty. Use at your own risk!

 

/*
Today's date: 2024-10-18
Expires tomorrow: 2024-10-19
*/

// Get today's date
var today = new Date();
var year = today.getFullYear().toString();
// Extract the month... Months are zero indexed, so add one!
var month = ("0" + (today.getMonth() + 1)).slice(-2);
var date = ("0" + today.getDate()).slice(-2);
var yyyymmdd = year.toString() + month.toString() + date.toString();
// Convert the string back to a number
yyyymmdd = parseInt(yyyymmdd);

// Conditional
if (yyyymmdd < 20241019) {
    // Add your code below. Remove the following alert...
    alert("Pass");
} else {
    // Do nothing on fail. Remove the following alert...
    alert("Fail");
}

 

3 replies

Stephen Marsh
Community Expert
Community Expert
October 21, 2024

Cross posted here:

 

<merged link removed>

 

MJ STAuthor
Known Participant
October 21, 2024
Legend
October 18, 2024

This is not Java and has nothing to do with writing an Android app.

Legend
October 17, 2024

This makes no sense. Javascript files don't have expiration dates. Can you give a better explanation?

Stephen Marsh
Community Expert
Community Expert
October 18, 2024

@Lumigraphics 

 

I’m guessing that this is an attempt at some sort of "licensing" or "time-limited working demo" for a script (not an extension/panel). But guess is just that, a guess. 

 

@MJ ST - Can you expand on your post?

try67
Community Expert
Community Expert
October 19, 2024

..


You must move all the code inside the curly brackets, next to the "put code here" comment.