I'm getting data in this format by implementing the below snippet.
I tried this:
$('#startDate').datetimepicker({
format: 'dd MM yyyy'
});
$('#endDate').datetimepicker({
format: 'dd MM yyyy',
useCurrent: false //Important! See issue #1075
});
This is working fine for me
$('#startDate').datetimepicker({
format: 'DDMMMYY'
});
$('#endDate').datetimepicker({
format: 'DDMMMYY',
useCurrent: false //Important! See issue #1075
});
in bootstrap 3 standard datepicker that I used. Here MMM is for three character abbreviated month and MMMM is for full abbreviation of month similarly DD is for 2 digit days with leading zeros and YY for 2 digit year with leading zeroes.
Related
I have a date in a format:
var date = "21 Sep 2017 14:00"
I want to change this date into en-US (in other words local) without the timezone. Which i guess should be:
"Sep 21 2017";
When i do this (I thought i would need to tell moment what the format of my date was):
moment.utc(date).local().format('DD MMM YYYY') it outputs "21 Sep 2017"
but if i do:
moment.utc(date).local().format() it still outputs "21 Sep 2017"
To test, I have been changing my regional settings from en-GB to en-US and it seems to make no difference.
What am i doing wrong here?
How do i convert the date to the local setting (and test it locally too)
I'm in en-GB
EDIT:
Re comments - Why then does this not say Set rather than Sep:
http://jsfiddle.net/rLjQx/5744/
As docs states:
By default, Moment.js comes with English (United States) locale strings. If you need other locales, you can load them into Moment.js for later use.
So first of all be sure that you are loading all required locales (see Loading locales in the browser or Loading locales in NodeJS).
Then you have to use locale() method to change locale of a moment object, local() is a different function. Note that moment usually uses 2 digit local code, so if you want to set locale to italian you have to use 'it' instead of "it-IT". You can find a full list of supported locales here.
Finally, since your input is not in a format recognized by moment(String) (ISO 8601 or RFC 2822), you have to use moment(String, String), as Matt Johnson highlighted in the comments.
Here a live example:
// var date = "21 Sep 2017 14:00";
// moment.utc(date, 'DD MMM YYYY HH:mm').local().format('DD MMM YYYY');
var m = moment("21 Sep 2017", 'DD MMM YYYY');
var formatted = m.locale("it").format("DD MMM YYYY");
$("#TestIT").text(formatted);
formatted = m.locale("en").format("DD MMM YYYY");
$("#TestEN").text(formatted);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment-with-locales.min.js"></script>
<div id="TestIT"></div>
<div id="TestEN"></div>
My data looks like this:
[{ x="2013-06-01", y=3}, { x="2013-07-01", y=7 }, { x="2013-08-01", y=3 }]
Chart x-axis is formatted as so:
chart.xAxis
.axisLabel('Date')
.tickFormat(function(d) { return d3.time.format('%b %Y')(new Date(d)); })
;
%b returns May, Jun, July respectively for the dates 2013-06-01, 2013-07-01, 2013-08-01
Why is it returning the previous month, and how can I fix it?
EDIT: If the date is formatted as 2013-06-02, it will return the correct month... does someone know what is happening to cause this?
#Amelia is correct it's because of timezone difference and because Date defaults to 24:00:00 if you don't specify a time. So, in case of EDT, which is -4:00, you lose 4 hours which puts you in the previous day (May 31 2013 20:00:00) and because the days in your dates are 01, this puts you in the previous month.
To bypass this you could append a time to your date if that is allowable in your case.
chart.xAxis
.axisLabel('Date')
.tickFormat(function(d) {
d = d.split('-')
// Create new date by using new Date(year, month, day, hour, second, ms)
// Subtracting 1 is necessary since Javascript months are 0 - 11.
return d3.time.format('%b %Y')(new Date(d[0], +d[1] - 1, d[2], 12, 0, 0));
});
Here is a working Fiddle
I'm trying to suit well this plugin pickadate.js v3.3.1 but I'm facing some difficulties.
First, I need to restrict selection of only future dates, 3 months from today's date. The docs didn't help me much so tried to do it this way. But it's not working.
Second, can I change this to a MONTH PICKER only? I need this for a Credit Card Expiry date field input.
The documentation isn't very great, But I guess being a new plugin I can use some good help of geeks here.
<script>
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+3;
$('#pickdate').pickadate({
// Escape any “rule” characters with an exclamation mark (!).
format: 'mmm dd , yyyy',
formatSubmit: 'yyyy/mm/dd',
hiddenPrefix: 'prefix__',
hiddenSuffix: '__suffix',
min: new Date(),
max: mm
//min: new Date(),
//max: (new Date() + 10)
})
$('#picktime').pickatime();
</script>
From the docs:
If dateMax or dateMin is an integer, it represents the relative number
of days till the min or max date.
I couldn't find any mentioning in the docs of a month picker. Why not use a standard dropdown ()?
What could prove to be of use to you with regards to range, again from the docs, is:
dateMin and dateMax can be either
an array representing a date ([ yyyy, mm, dd ])
I have the following code
String test = "21/04/2013";
fmt = DateTimeFormat.getFormat("MM/dd/yyyy");
Date dateTest = fmt.parse(test);
Window.alert(fmt.format(dateTest));
And the alert box shows the date
09/04/2014
instead of
21/04/2013
Why?
As others already say, it's because of your pattern. What they don't say is why it behaves that way.
When parsing 21/04/2013 as MM/dd/yyyy, DateTimeFormat will decompose the date as:
Month Day of month Year
21 4 2013
and it'll then adjust things to make a valid date. To do that, the Month part is truncated at 12 (so that temporary date is Dec 4th, 2013) and the remainder (21 - 12 = 9) is then added, leading to Sept. 4th 2014, which according to your format displays as 09/04/2014.
You wanted to show 21/04/2013 but the format was MM/dd/yyyy.
It should be dd/MM/yyyy
So change it like this:
String test = "21/04/2013";
fmt = DateTimeFormat.getFormat("dd/MM/yyyy");
Date dateTest = fmt.parse(test);
Window.alert(fmt.format(dateTest));
You're reversing day and month.
String test = "21/04/2013";
fmt = DateTimeFormat.getFormat("dd/MM/yyyy");
Date dateTest = fmt.parse(test);
Window.alert(fmt.format(dateTest));
I have a string of the format Jan 25, 2011 3:17 AM. I need to convert it to NSDate.
I used NSDateFormatter with format #"MMM d, yyyy h:mm a". It Works well if iphone time is in 12 hr format, but returns nil if time is in 24 hr format. Can any one help me with this????
Capital H is used for 24 hour format. Don't 24 hour times usually exclude the AM/PM part? If so, your format string should be: #"MMM d yyyy H:mm".
Here's a reference for Unicode date format strings.
It's a bug in NSDateFormatter. You can work around it by manually setting a locale on the date formatter:
[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:#"en_GB"] autorelease]];