I have an unusual date formatting issue that, perhaps, someone else has encountered.
I have an MVC application with textboxes with #class = datepicker.
I have a global formatting string (dd-MMM-yyyy)
There's a bit of JS:
$(function () {
$('.datepicker').datepicker({
format: 'dd-MMM-yyyy',
autoclose: true
});
});
Issue: When I click on the textbox and select a date, I get something like the following:
01-JanuaryJan-2017
I assumed that, maybe, i had some formatting somewhere like dd-MMMMMMM-YYYY, but I do not. I'm at a loss.
I've inherited this application and am not extremely well-versed in web development, but this seems like an issue that I should be able to figure out.
I realize i don't have a lot of details here, but I'm also only looking for generic/high-level solutions like:
Check in this general area, or look for this, etc.
You have a wrong format. Use the right one from the following (as you wish):
format: 'dd-MM-yy'
which will display the date like this 03-January-2017
OR
format: 'dd-M-yy'
which will display the date like this 03-Jan-2017
Here is the (incomplete) list of valid values for the dateFormat property from the jQueryUI DatePicker Docs:
The format can be combinations of the following:
d - day of month (no leading zero)
dd - day of month (two digit)
o - day of the year (no leading zeros)
oo - day of the year (three digit)
D - day name short
DD - day name long
m - month of year (no leading zero)
mm - month of year (two digit)
M - month name short
MM - month name long
y - year (two digit)
yy - year (four digit)
# - Unix timestamp (ms since 01/01/1970)
! - Windows ticks (100ns since 01/01/0001)
'...' - literal text
'' - single quote
anything else - literal text
So, in your case, you are combining MM, which is the full month name with M which is the short month name, resulting in JanuaryJan.
Related
Hi i have been working on the final question for my assignment and i have to check if today's date is greater than a date that is store as a number in a database. ie today's date would be 16122017 dd mm yy as you can see it has no spaces or a "-" or "/" just a number. i can get todays date reverse it and remove the - but a simple < or > does not work for comparison as they are numbers not java date formats.
So i figure i have to add the - back into the date and reverse it so it yy mm dd and then compare it to the current date.
Can any one show me how to add - into the number format, i can simply reverse it back to yy mm dd from dd mm yy once done with
> c = c.split('-').reverse().join('');
where c is the var containing the number date. i assume once it has - back in it i could just do
if (c > LocalDate.now())
or do i need to assign it to a new date var ?
There are some cool addon packages like moment.js that can do this with an elegant call. But, in native javascript you can do this sort of thing, using the handy-dandy setFullYear(y,m,d) function.
var ds = '16122017'
var myDate = new Date();
myDate.setFullYear(ds.substring(4,8),ds.substring(2,4)-1,ds.substring(0,2));
var today = new Date();
today.setHours (0,0,0,0); /* turn now into today */
if (myDate < today) {
/* myDate was before today */
}
Besides using a library that can convert the dates for you, I suggest the good old substring method if you know for sure that the first two numbers are the day, then month, then year, such that
var day = str.substring(1, 2);
and so on. Then you create a new Date object based on your calculations and work with it.
If your input doesn't have trailing zeros, that adds complexity to the problem, but nothing that you can't overcome.
I need to get the start date and end date in the below format using moment js
startDate = 20160427000000 and
endDate = 20160427235959
Here the start date appended with 000000 and end date appended with 235959
What is the right way to get this result in javascript
You want the format operator. Since it looks like your 0's and 2359's are hardcoded (I assume you're doing start and end of days), try:
startDate = moment().format('YMMDD000000');
endDate = moment().format('YMMDD235959');
EDIT: Or, as RobG pointed out, you can use:
startDate = moment().startOf('day').format("YMMDDHHmmss");
endDate = moment().endOf('day').format("YMMDDHHmmss");
(Which is much neater)
I'm totally confused, I don't know if you want to parse the format or output it. If you want to parse dates using moment.js in that format, then in time zone +05:30:
// Format YYYYMMDDHHmmss for 2016-04-26T00:00:00
var s = '20160426000000';
var x = moment(s, 'YYYYMMDDHHmmss');
// Show date in ISO 8601 extended format
console.log(x.format()); // 2016-04-26T00:00:00+05:30
To shift to the end of the day and output in YYYMMDDHHmmss format:
console.log(x.endOf('day').format('YYYYMMDDHHmmss')); // 20160426235959
In the format string:
YYYY is 4 digit year
MM is two digit month
DD is two digit day
HH is two digit hour in 24 hour format
mm is two digit minute
ss is two digit seconds
For Getting Format Like these in moment.js - (2020-12-15T13:00:00)
let a =2023-01-14T20:15:00-05:00
You can use moment(a).format("YYYY-MM-DDTHH:mm:ss")
Result: 2023-01-14T20:15:00
I am creating a platform for recurring monthly orders.
I am using later.js for the recurrence. I have come across the following two cases and I am wondering if anybody has suggestions on how to better handle these (or if later.js handles them natively somehow):
later.parse.recur().on(31).dayOfMonth()
The date is the 31st of a given month. Current result is that is jumps months that end on the 30th. WORKAROUND: is to use last().dayOfMonth().
later.parse.recur().on(30).dayOfMonth()
later.parse.recur().on(31).dayOfMonth()
Month of February, ending on the 28th or 29th. How to handle if the date is 30th (or 31st). WORKAROUND: If date > 28th, add .and().on(59).dayOfYear()
Thanks!
I don't know the specifics of later.js, but apparently you can write something called a custom modifier: https://github.com/bunkat/later/blob/master/example/modifier.js
In addition to this, if you add a month to a javascript date (doesn't matter if the number becomes greater than 11/december), set the day of the month to the first then subtract 1 day, then you'll get the date of the last day in the originally given month. For example:
var a = new Date("2000-02-25");
var b = new Date(new Date(a.getFullYear(),a.getMonth()+1,1)-1);
console.log(b);
I am trying to fetch the video data from YouTube API.
This is my request:
https://www.googleapis.com/youtube/v3/search?key={{YOUKEY}}&channelId={{CHANNELID}}&part=snippet,id&order=date&maxResults=50&publishedAfter=2014-09-21T00:00:00Z&publishedBefore=2014-09-22T02:00:00Z
As you can see in this, the publishedAfter is in this way
2014-09-21T00:00:00Z with time set to zero. I tried using moment, but couldn't get the exact format.
the default moment.format() Date is displayed like you ask, however you could force it by using a format string like
moment(string).format('YYYY-MM-DDThh:mm:ss[Z]');
explanation
YYYY year in digits
MM month in digits (base 1)
DD day of year in digits
T a random letter
hh:mm:ss hour:minutes:seconds
[Z] escape sequence for printing the letter Z
the letter Z in the format string in fact prints the time zone, as seen in the docs.
the exact solution is
var formatString = 'YYYY-MM-DDT[00:00:00Z]';
moment(string).format(formatString);
fiddle
I have problem with String > Format of timezone.
I have string: " 2015-02-10 00:00:00,3,UTC "
And try to format it in moment:
moment('2015-02-10 00:00:00,3,UTC', 'YYYY-MM-DD HH:mm:ss, ?, ?')
What should I insert instead of "?"
It's not possible to format that kind of string into moment because a lone 3 does not designate the timezone offset in any standard format.
You need to change the 3 into +0030.
This should work:
var date = '2015-02-10 00:00:00,3,UTC'
.replace(/,(\d\d),/,',+$100,') // for double digit cases (11 turns to +1100)
.replace(/,(\d),/,',+0$100,'); // single digit cases (3 to +0300)
And then
moment(date, 'YYYY-MM-DD HH:mm:ss,ZZ')
I'm not sure what the UTC part is about since +0300 is clearly not UTC. I guess it's just saying that the the 3 hour offset is relative to UTC?