Get current week javascript

Get current week javascript

Learn Latest Tutorials

Splunk tutorial

SPSS tutorial

Swagger tutorial

T-SQL tutorial

Tumblr tutorial

React tutorial

Regex tutorial

Reinforcement learning tutorial

R Programming tutorial

RxJS tutorial

React Native tutorial

Python Design Patterns

Python Pillow tutorial

Python Turtle tutorial

Keras tutorial

Preparation

Aptitude

Logical Reasoning

Verbal Ability

Company Interview Questions

Artificial Intelligence

AWS Tutorial

Selenium tutorial

Cloud Computing

Hadoop tutorial

ReactJS Tutorial

Data Science Tutorial

Angular 7 Tutorial

Blockchain Tutorial

Git Tutorial

Machine Learning Tutorial

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures tutorial

DAA tutorial

Operating System

Computer Network tutorial

Compiler Design tutorial

Computer Organization and Architecture

Discrete Mathematics Tutorial

Ethical Hacking

Computer Graphics Tutorial

Software Engineering

html tutorial

Cyber Security tutorial

Automata Tutorial

C Language tutorial

C++ tutorial

Java tutorial

.Net Framework tutorial

Python tutorial

List of Programs

Control Systems tutorial

Data Mining Tutorial

Data Warehouse Tutorial

Javatpoint Services

JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.

  • Website Designing
  • Website Development
  • Java Development
  • PHP Development
  • WordPress
  • Graphic Designing
  • Logo
  • Digital Marketing
  • On Page and Off Page SEO
  • PPC
  • Content Development
  • Corporate Training
  • Classroom and Online Training
  • Data Entry

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week

Like/Subscribe us for latest updates or newsletter RSS Feed Subscribe to Get Email Alerts Facebook Page Twitter Page YouTube Blog Page

Источник

Get current week javascript

Learn Latest Tutorials

Splunk tutorial

SPSS tutorial

Swagger tutorial

T-SQL tutorial

Tumblr tutorial

React tutorial

Regex tutorial

Reinforcement learning tutorial

R Programming tutorial

RxJS tutorial

React Native tutorial

Python Design Patterns

Python Pillow tutorial

Python Turtle tutorial

Keras tutorial

Preparation

Aptitude

Logical Reasoning

Verbal Ability

Company Interview Questions

Artificial Intelligence

AWS Tutorial

Selenium tutorial

Cloud Computing

Hadoop tutorial

ReactJS Tutorial

Data Science Tutorial

Angular 7 Tutorial

Blockchain Tutorial

Git Tutorial

Machine Learning Tutorial

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures tutorial

DAA tutorial

Operating System

Computer Network tutorial

Compiler Design tutorial

Computer Organization and Architecture

Discrete Mathematics Tutorial

Ethical Hacking

Computer Graphics Tutorial

Software Engineering

html tutorial

Cyber Security tutorial

Automata Tutorial

C Language tutorial

C++ tutorial

Java tutorial

.Net Framework tutorial

Python tutorial

List of Programs

Control Systems tutorial

Data Mining Tutorial

Data Warehouse Tutorial

Javatpoint Services

JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.

  • Website Designing
  • Website Development
  • Java Development
  • PHP Development
  • WordPress
  • Graphic Designing
  • Logo
  • Digital Marketing
  • On Page and Off Page SEO
  • PPC
  • Content Development
  • Corporate Training
  • Classroom and Online Training
  • Data Entry

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week

Like/Subscribe us for latest updates or newsletter RSS Feed Subscribe to Get Email Alerts Facebook Page Twitter Page YouTube Blog Page

Источник

IamSilviu / Get week number

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

Date.prototype.getWeek = function ()
var onejan = new Date(this.getFullYear(), 0, 1);
return Math.ceil((((this — onejan) / 86400000) + onejan.getDay() + 1) / 7);
>;
var myDate = new Date(«2001-02-02»);
myDate.getWeek(); //=> 5

Nice. But if date includes non-zero hours or minutes, result is incorrect. This helps:

var onejan = new Date(this.getFullYear(), 0, 1);
return Math.ceil((((new Date(this.getFullYear(), this.getMonth(), this.getDate()) — onejan) / 86400000) + onejan.getDay() + 1) / 7);

The same function with small refactoring:

function getNumberOfWeek()  const today = new Date(); const firstDayOfYear = new Date(today.getFullYear(), 0, 1); const pastDaysOfYear = (today - firstDayOfYear) / 86400000; return Math.ceil((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7); >

how to find week number in a month in javascript

how to find week number in a month in javascript

The same function with small refactoring:

function getNumberOfWeek()  const today = new Date(); const firstDayOfYear = new Date(today.getFullYear(), 0, 1); const pastDaysOfYear = (today - firstDayOfYear) / 86400000; return Math.ceil((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7); >

The same function with small refactoring:

function getNumberOfWeek()  const today = new Date(); const firstDayOfYear = new Date(today.getFullYear(), 0, 1); const pastDaysOfYear = (today - firstDayOfYear) / 86400000; return Math.ceil((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7); >
function getNumberOfWeek(date) < const firstDayOfYear = new Date(date.getFullYear(), 0, 1); const pastDaysOfYear = (date - firstDayOfYear) / 86400000; return Math.ceil((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7); >function ISO8601_week_no(dt) < var tdt = new Date(dt.valueOf()); var dayn = (dt.getDay() + 6) % 7; tdt.setDate(tdt.getDate() - dayn + 3); var firstThursday = tdt.valueOf(); tdt.setMonth(0, 1); if (tdt.getDay() !== 4) < tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7); >return 1 + Math.ceil((firstThursday - tdt) / 604800000); > console.log('============================='); dt = new Date(2015, 10, 1); < let time = performance.now(); console.log(ISO8601_week_no(dt)); //44 time = performance.now() - time; console.log('Время выполнения1 = ', time); > < let time = performance.now(); console.log(getNumberOfWeek(dt)); // 45 time = performance.now() - time; console.log('Время выполнения12 = ', time); >
function getNumberOfWeek()  const today = new Date(); const firstDayOfYear = new Date(today.getFullYear(), 0, 1); const pastDaysOfYear = (today - firstDayOfYear) / 86400000; return Math.ceil((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7); >

There is just small issue that typescript don’t validate arithmetic operations on Date type so shows below error.

The left-hand side of an arithmetic operation must be of type ‘any’, ‘number’ or an enum type

So I’ve called .valueOf() on Dates in that arithmetic operation.

getNumberOfWeek(): number  const today = new Date(); const firstDayOfYear = new Date(today.getFullYear(), 0, 1); const pastDaysOfYear = (today.valueOf() - firstDayOfYear.valueOf()) / 86400000; return Math.ceil((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7); >

Источник

Читайте также:  Python directory file type
Оцените статью