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?

MJ STAuthor
Known Participant
October 18, 2024

Sure it can be done, in it's simplest form:

 

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

 

However you will likely need to research how to work with date stamps in JavaScript, then create a simple conditional if/else block to wrap around your code to compare if today's date is less than a target expiry date.

 

You will need to obfuscate the code and or create an encrypted .jsxbin version of the .jsx code, which isn't bulletproof. This doesn't stop the system clock being changed to extend the expiry of the script. So you could script the writing of the date of the first run of the script to a "hidden" text file and then validate the date by reading the text file. But this isn't bulletproof either as the new text file could be logged or found etc. There will always be ways to cheat this, so it comes down to how hard you want to make this.

 

https://www.davidebarranca.com/2016/07/html-panel-tips-22-protecting-your-code/

 

https://www.davidebarranca.com/2017/02/html-panel-tips-23-javascriptobfuscator-api-gulp-js-plugin/

 

 


Yes, I understand. But I am not able to use the code. I am giving you the script. Can you enter the code please?