Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Get month name with javascript

Explorer ,
Aug 18, 2022 Aug 18, 2022

Hello everyone,

 

I'm a nooby in coding so I need your help. I would like to get the month name when i'm lauching this script in illustrator. For the moment when I launch the script I get this: 08/2022
I would like to get this: august 2022
Thank you


var WR="Concepteur SAI - ";

var AIversion=version.slice(0,2);

var format_preset = "N.F.X 08-070 DE JUIN 2013 DATE DE CONCEPTION DU PLAN: {DATE} - {FILENAME}";

var MSG_unsetmark = WR+"This object is marked as actual date'n'time, do you want to remove the mark?";
var MSG_setmark = WR+"Do you want to mark the selected textobject as actual date'n'time?";
var MSG_askformat = WR+"Do you want to mark the textobject as actual date'n'time? Formats:\n{DATE} - {TIME} - {FILE} - {FILEPATH} - {FILENAME} and {FILEEXT}:"
var MSG_editformat = WR+"Edit date'n'time (empty = remove). Formats:\n{DATE}, {TIME}, {FILE}, {FILEPATH}, {FILENAME} and {FILEEXT}:"
var MSG_notexto = WR+"Pas de texte!";
var MSG_selectedmany = "Vous devez dans un premier temps selectionner le texte du concepteur avant d'exécuter ce script.";
var MSG_nodocs = WR+"Vous n'avez pas de document ouvert."
var Timeformat = 24;
var TimeSep = ":";
var AM = " am";
var PM = " pm";
var Dateformat = "mm/yyyy";


var error=0;

if (documents.length<1) {
error++;
alert(MSG_nodocs)
}

if (error < 1) {
date_n_time();
}

function TodayDate()
{
var Today = new Date();
var Day = Today.getDate();
var Month = Today.getMonth() + 1;
var Year = Today.getYear();
var PreMon = ((Month < 10) ? "0" : "");
var PreDay = ((Day < 10) ? "0" : "");
if(Year < 999) Year += 1900;

var theDate = Dateformat.replace(/dd/,PreDay+Day);
theDate = theDate.replace(/mm/,PreMon+Month);
theDate = theDate.replace(/d/,Day);
theDate = theDate.replace(/m/,Month);
theDate = theDate.replace(/yyyy/,Year);
theDate = theDate.replace(/yy/,Year.toString().substr(2,2));

return theDate;
}

function TodayTime()
{
var Today = new Date();
var Hours = Today.getHours();
var Minutes = Today.getMinutes();
var Suffix = "";
if (Timeformat == 12) {
if (Hours >= 12 ) {
Suffix = PM;
} else {
Suffix = AM;
}
if (Hours >= 13) {
Hours = Hours - 12;
}
if (Hours < 1) {
Hours = Hours + 12;
}
}
var PreHour = ((Hours < 10) ? "0" : "");
var PreMin = ((Minutes < 10) ? "0" : "");
return PreHour+Hours+TimeSep+PreMin+Minutes+Suffix;
}

function DateUpdate(Name) {
var docpath = activeDocument.path.fsName;
var docname = activeDocument.name.replace(/(.*?)(?:\.([^.]+))?$/,'$1');
var extension = activeDocument.name.replace(/(.*?)(?:(\.[^.]+))?$/,'$2');
if (docpath.slice(2,3) == "\\") {
docsep = "\\";
} else {
docsep = ":";
}
var content = Name.slice(11);
var content = content.replace(/\{FILE\}/,docpath+docsep+docname);
var content = content.replace(/\{FILEPATH\}/,docpath);
var content = content.replace(/\{FILENAME\}/,docname);
var content = content.replace(/\{FILEEXT\}/,extension);
var content = content.replace(/\{DATE\}/,TodayDate());
var content = content.replace(/\{TIME\}/,TodayTime());
return content;
}

function date_n_time()
{
if (selection.length == 1) {
if (selection[0].typename == "TextArtItem" || selection[0].typename == "TextFrame") {
if (selection[0].name.slice(0,11) == "actualDate:") {
dateformat = selection[0].name.slice(11);
Check = false;
if (AIversion == "10") {
Check = confirm( MSG_unsetmark );
} else {
dateformat = prompt(MSG_editformat, dateformat);
}
if(dateformat != "" && Check) {
selection[0].contents = selection[0].name.slice(11);
selection[0].name="";
selection[0].selected = false;
}
if(dateformat == "" && !Check) {
selection[0].name="";
selection[0].selected = false;
}
if(dateformat && dateformat !="" && !Check) {
selection[0].name="actualDate:"+dateformat;
selection[0].contents = DateUpdate(selection[0].name);
}
} else {
dateformat = selection[0].contents;
if(dateformat.search(/\{DATE\}/) == -1 && dateformat.search(/\{TIME\}/) == -1 && dateformat.search(/\{FILE[A-Z]*\}/) == -1) dateformat = format_preset;
Check = false;
if (AIversion == "10") {
Check = confirm( MSG_setmark );
} else {
dateformat = prompt(MSG_askformat, dateformat);
}
if (dateformat || Check) {
selection[0].name="actualDate:"+dateformat;
selection[0].contents = DateUpdate(selection[0].name);
selection[0].selected = false;
}
}
} else {
alert ( MSG_notexto );
}
} else if (selection.length > 1) {
alert ( MSG_selectedmany );
} else {
if (AIversion == "10") {
var textArtItems = activeDocument.textArtItems;
for (var i = 0 ; i < textArtItems.length; i++)
{
if (textArtItems[i].name.slice(0,11) == "actualDate:") {
textArtItems[i].selected = true;
textArtItems[i].contents = DateUpdate(textArtItems[i].name);
}
}
} else {
var textFrames = activeDocument.textFrames;
for (var i = 0 ; i < textFrames.length; i++)
{
if (textFrames[i].name.slice(0,11) == "actualDate:") {
textFrames[i].selected = true;
textFrames[i].contents = DateUpdate(textFrames[i].name);
}
}
}
}
}

TOPICS
Scripting
460
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 18, 2022 Aug 18, 2022

Try this

var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
var today = new Date()
alert(months[today.getMonth()] + " " + (today.getYear() + 1900))

-Manan

Translate
Adobe
Community Expert ,
Aug 18, 2022 Aug 18, 2022

Try this

var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
var today = new Date()
alert(months[today.getMonth()] + " " + (today.getYear() + 1900))

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 18, 2022 Aug 18, 2022

I tried but it failed.. I think I placed your script at the wrong place in my script

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 18, 2022 Aug 18, 2022
LATEST

It works !! Thank you so much

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines