jacwright / date.format Goto Github PK
View Code? Open in Web Editor NEWA JavaScript date format library that uses the same method as PHP's date() function.
License: MIT License
A JavaScript date format library that uses the same method as PHP's date() function.
License: MIT License
Jacob,
Will you add this to date.format.js for Quarter? If this code is not correct, please let me know what's wrong with it.
// Quarter
Q: function() { var d = new Date(); return Math.floor((d.getMonth() + 3) / 3); },
Thanks!
Tim Allums
Hello!
I am doing this:
var date_obj = new Date('2014-12-29');
var week_number = date_obj.format('W'); // returns 1
Same thing for 30 and 31 ( probably related to a fact that 29th is Monday)
Thanks,
Andrey
I realized that something is wrong with the week calculation when I received constantly incorrect results. After some digging I found out that it must be an ISO implementation bug.
ISO 8601 states that week 1 is the week with the first Thursday of that year.
Sat Aug 16 2014 02:00:00 GMT+0200 (CEST)
Week number: 34
Week number: 33
I found this article, in which the code in Date.getWeek() section seems to have a working solution.
Hi, hi.
Display wrong week number with W
for this use cases:
currentWeekNumber("March 24, 2015")
//=> 13
currentWeekNumber("03/24/2016")
//=> 13, must be 12
currentWeekNumber("August 07, 2015")
//=> 32, that's okey
currentWeekNumber("02/16/2015")
//=> 7, nope, must be 8
Any ideas? I try to beat it from few hours, but.. I'm not lucky guy.
This is little extended code:
module.exports = function currentWeekNumber(date) {
var instance, inst;
if (date && typeof date === 'string' && date !== '') {
instance = new Date(date);
} else {
instance = new Date();
}
inst = new Date(instance.getFullYear(), 0, 1);
return Math.ceil((((instance - inst) / 86400000) + inst.getDay() + 1) / 7);
}
Before I found this repo, I use current-day-number and was near to truth
var currentDayNumber = require('current-day-number');
module.exports = function currentWeekNumber(date) {
date = date || "";
return ((currentDayNumber(date) / 7) +1.24) | 0;
};
Really... I can't realize why hole this shit is happening. :D
for example. I am currently in EDT.
the utc timestamp = 1394355600000
d = new Date(utc) gives me
Date 2014-03-09T09:00:00.000Z
d.format('T') gives EST which is wrong.
d.format('T') should give EDT.
When .toString() returns "Wed Sep 24 2014 22:52:48 GMT+0530 (IST)",
.format('c') returns "2014-09-24T22:52:48+05.5:00"
which seems invalid.
In Chrome's console:
new Date(1534545439635);
Sat Aug 18 2018 00:37:19 GMT+0200 (Central European Summer Time)
new Date(1534545439635).format("z");
"229"
The same day but later:
new Date(1534588427903)
Sat Aug 18 2018 12:33:47 GMT+0200 (Central European Summer Time)
new Date(1534588427903).format("z");
"230"
The timestamp at 00:37:19 returns "229" but the timestamp of the same day at 12:33:47 returns "230"
Note: Central European Summer Time is GMT +02:00 ;)
Can you please publish this package on bower?
Hi Jan,
I just noticed the variable d is defined twice:
d: function() { var d = this.getDate(); return (d < 10 ? '0' : '') + d; },
and
z: function() { var d = new Date(this.getFullYear(),0,1); return Math.ceil((this - d) / 86400000); },
I think the second one should beȘ
z: function() { var z = new Date(this.getFullYear(),0,1); return Math.ceil((this - z) / 86400000); },
your package name is date_format in bower, but you mentioned date-format in readme file which is related to another bower package.
Hi,
is there a good reason to ditch the semicolon at the end of the file? We use it in our project concatenated with other JS libraries. And if missing it breaks the whole concatenated output.
Also why is there no minified version anymore?
Using format charackter "O", should show difference to Greenwich time (GMT) in hours (I think this is RFC 822 time zone). It is working fine with integer hours. For time zones with half an hour differences (eg. Kabul Afganistan) instead of showing +0430 it is showing +04.500
It'd be great to be able to npm install this module and require it.
Hi Guys
When using M I get this:
Uncaught TypeError: Cannot read property 'shortMonths' of undefined date.format.js:23
When using F I get this:
Uncaught TypeError: Cannot read property 'longMonths' of undefined date.format.js:21
"m" and "n" appear to work fine though!
Any ideas?
PHP uses zero-based numbering for "z" in date formatting and returns values from 0 - 365. This library returns values from 1 - 366.
In my opinion, to fully mimic PHP, the function should end with a subtraction of 1:
(linebreaks added for readability)
z: function () {
var d = new Date(this.getFullYear(), 0, 1);
return Math.ceil((this - d) / 86400000) - 1
},
Or was there a motivation to not used zero-based numbering here?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.