10 examples of 'javascript get year' in JavaScript

Every line of 'javascript get year' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
80function getDayOfYear(date,utc) {
81 utc = utc || false;
82 var dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
83 var mn = utc ? date.getUTCMonth() : date.getMonth();
84 var dn = utc ? date.getUTCDate() : date.getDate();
85 var dayOfYear = dayCount[mn] + dn;
86 if(mn > 1 && isLeapYear(utc ? date.getUTCFullYear() : date.getFullYear())) dayOfYear++;
87 return dayOfYear;
88}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

42function getYear(date) {
43 return moment(date).jYear();
44}
133Utils.prototype.getYear = function getYear(date) {
134 return date.jYear();
135};
449function getYear(){
450 var year = "";
451 if(document.title)
452 {
453 var mName = document.title.substr(0, document.title.indexOf(" -")).replace(/ /g, "+");
454 year = mName.substr(document.title.indexOf("(")+1).replace(")","");
455 }
456 return year;
457}
26function dayFromYear(y) {
27 return Math.floor((y - 1969) / 4) - Math.floor((y - 1901) / 100) + Math.floor((y - 1601) / 400) + 365 * (y - 1970);
28}
88getFullYear () {
89 return this.jdate[0]
90}
21get year() {
22 return this._year;
23}
5function completeYear(year) {
6 if(year.length == 2) {
7 var currentYear = new Date().getFullYear();
8 if (parseInt(year) <= currentYear % 100)
9 return Math.floor(currentYear/100) + year;
10 else
11 return (Math.floor(currentYear/100) - 1) + year;
12 }
13 return year
14}
164firstDayOfYear(): number {
165 return this._week.doy;
166}
44var getImperialYear = function getImperialYear(year) {
45 var langLocale = $A.get("$Locale.langLocale");
46 var useShortName = langLocale !== "ja";
47 for (var i = 0; i < imperialYear.length; i++) {
48 if (year >= imperialYear[i].year) {
49 var ret = getImperialYearLabel(imperialYear[i], useShortName) + (year - imperialYear[i].year + 1);
50 if (year === imperialYear[i].year && i < imperialYear.length - 1) {
51 // transition year -- display both
52 var prev = imperialYear[i + 1];
53 ret += '/' + getImperialYearLabel(prev, useShortName) + (year - prev.year + 1);
54 }
55 return ret;
56 }
57 }
58 return null;
59};

Related snippets