With this code, I able to get selected date as unix. jsfiddle
function getValue() {
var date = $('#example').data("DateTimePicker").date();
if( date ){
alert(date.unix());
}
}
How about PersianDate, I want to get selected date as unix. jsfiddle
CodePudding user response:
You can do it by using getState
method on persianDatepicker
instance, like this:
var pd = $('#example').persianDatepicker({
autoClose: true,
// other options
});
function showUnix() {
const state = pd.getState();
alert(state.selected.unixDate);
}
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://babakhani.github.io/PersianWebToolkit/doc/lib/persian-date/dist/persian-date.js"></script>
<script src="https://babakhani.github.io/PersianWebToolkit/doc/lib/persian-datepicker/dist/js/persian-datepicker.js"></script>
<link href="https://unpkg.com/persian-datepicker@latest/dist/css/persian-datepicker.min.css" rel="stylesheet" />
<input type="text" id="example" >
<button onclick="showUnix()">show unix</button>
CodePudding user response:
https://jsfiddle.net/mplungjan/fbo09p25/
Add a hidden field with the ERA value or use a change handler
$('#example').persianDatepicker({
observer: true,
altField: '#example_era',
onSelect: function(unix){
console.log('datepicker select : ' unix);
},