Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you adjust the font and font family on this date script [duplicate]

Is there a way to add a font: Arial and color: White to this script?

<script>
            var date = new Date();
            days_change = -2;
            date.setDate(date.getDate() + days_change);
    
            const formattedDate = date.toLocaleString("en-GB", {
                day: "numeric",
                month: "long",
                year: "numeric",
            });
    
            document.write(formattedDate);
</script>
like image 884
James Jones Avatar asked Dec 21 '25 18:12

James Jones


1 Answers

As another solution.

You can wrap formattedDate in a <span>...</span> tag with a class. As here:

document.write("<span class='date_arial'>" + formattedDate + "</span>");

And add the desired styles to the CSS. As here:

.date_arial {
  font-family: Arial, sans-serif;
  color: #FFFFFF;
}

var date = new Date();
            days_change = -2;
            date.setDate(date.getDate() + days_change);
    
            const formattedDate = date.toLocaleString("en-GB", {
                day: "numeric",
                month: "long",
                year: "numeric",
            });
 
            document.write(formattedDate);
            
            document.write("<span class='date_arial'>" + formattedDate + "</span>");
body {
  background-color: green;
}

.date_arial {
  font-family: Arial, sans-serif;
  color: #FFFFFF;
}
like image 143
s.kuznetsov Avatar answered Dec 24 '25 06:12

s.kuznetsov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!