我想将 moment.js 的时间选择器的输入格式从 2018-01-23T12:38:07.439Z 更改为 12:38:07
I want to change input format of a timepicker of moment.js from 2018-01-23T12:38:07.439Z to 12:38:07
我正在使用 angular js material 作为模板,angular js 作为 js .并且由于 angular material js 中没有时间选择器,所以我使用的是 moment.js 的时间选择器 我正在使用 Django 作为 后端 。我通过 rest api 将数据放入数据库中 angular 模板的代码在这里:
<md-input-container flex-gt-sm class="md-block">
<label>Opening Time</label>
<md-icon md-svg-src="/cityaplfreelisting/media/time.svg" class="mdicon"></md-icon>
<input required mdc-datetime-picker date="false" time="true" type="text" short-time="true"
show-todays-date click-outside-to-close="true"
auto-ok="true"
min-date="minDate" minute-steps="1"
format="hh:mm a"
ng-change="vm.saveChange()"
ng-model="data.openingTime ">
</md-input-container>
实际上,我的数据库在 hh:mm:ss 中采用 openingTime 的值,直到其余 api 这就是为什么我想更改时间的输入格式,它以 2018-01-23T12:38:07.439Z 的格式显示,这对我的 django 模型
这是我的 django 模型
from django.db import models
from django.contrib.gis.db import models as gis_models
from django.contrib.postgres.fields import ArrayField
from django.conf import settings
from django.db.models.signals import pre_save
from django.utils.text import slugify
from multiselectfield import MultiSelectField
class Shop(models.Model):
city = models.ForeignKey(City, on_delete=models.CASCADE)
category = models.ForeignKey(Category, on_delete=models.CASCADE) # will change on_dlt method soon
subCategory = models.ManyToManyField(SubCategory)
filterTags = models.ManyToManyField(FilterTag, blank=True)
owner = models.ForeignKey(settings.AUTH_USER_MODEL,default=1)
slug = models.SlugField(unique=True, blank=True)
shopName = models.CharField(max_length=250)
tagline = models.CharField(blank=True, max_length=500)
bannerImage = models.ImageField(upload_to=upload_location,
default='shop/defaultimage/default.png',
width_field='widthField',
height_field='heightField')
widthField = models.IntegerField(default=0)
heightField = models.IntegerField(default=0)
likes = models.PositiveIntegerField(default=0)
dislikes = models.PositiveIntegerField(default=0)
email = models.EmailField(blank=True)
mobileNo = models.CharField(max_length=14)
alternateMobileNo = models.CharField(max_length=15, blank=True)
location = gis_models.PointField(u'longitude/latitude',
geography=True, blank=True, null=True)
ownerName = models.CharField(blank=True,max_length=250)
shopAddress = models.TextField()
shopPinCode = models.PositiveIntegerField()
openingTime = models.TimeField()
closingTime = models.TimeField()
closingDay = MultiSelectField(choices=DAYS,default=DAYS[7][0])
isActive = models.BooleanField(default=0)
updatedAt = models.DateTimeField(auto_now=True)
timestamp = models.DateTimeField(auto_now_add=True)
gis = gis_models.GeoManager()
objects = models.Manager()
def __str__(self):
return self.shopName
Here is the picture of my time picker
This is picture of json format of openingTime which I am putting through rset api
my django admin (only lower part
请告诉我应该怎么做才能使时间输入字段的输入时间格式可接受
您必须更改数据库时间字段的格式..您不能更改输入时间格式
我正在使用 angular js material 作为模板,angular js 作为 js .并且由于 angular material js 中没有时间选择器,所以我使用的是 moment.js 的时间选择器 我正在使用 Django 作为 后端 。我通过 rest api 将数据放入数据库中 angular 模板的代码在这里:
<md-input-container flex-gt-sm class="md-block">
<label>Opening Time</label>
<md-icon md-svg-src="/cityaplfreelisting/media/time.svg" class="mdicon"></md-icon>
<input required mdc-datetime-picker date="false" time="true" type="text" short-time="true"
show-todays-date click-outside-to-close="true"
auto-ok="true"
min-date="minDate" minute-steps="1"
format="hh:mm a"
ng-change="vm.saveChange()"
ng-model="data.openingTime ">
</md-input-container>
实际上,我的数据库在 hh:mm:ss 中采用 openingTime 的值,直到其余 api 这就是为什么我想更改时间的输入格式,它以 2018-01-23T12:38:07.439Z 的格式显示,这对我的 django 模型
这是我的 django 模型
from django.db import models
from django.contrib.gis.db import models as gis_models
from django.contrib.postgres.fields import ArrayField
from django.conf import settings
from django.db.models.signals import pre_save
from django.utils.text import slugify
from multiselectfield import MultiSelectField
class Shop(models.Model):
city = models.ForeignKey(City, on_delete=models.CASCADE)
category = models.ForeignKey(Category, on_delete=models.CASCADE) # will change on_dlt method soon
subCategory = models.ManyToManyField(SubCategory)
filterTags = models.ManyToManyField(FilterTag, blank=True)
owner = models.ForeignKey(settings.AUTH_USER_MODEL,default=1)
slug = models.SlugField(unique=True, blank=True)
shopName = models.CharField(max_length=250)
tagline = models.CharField(blank=True, max_length=500)
bannerImage = models.ImageField(upload_to=upload_location,
default='shop/defaultimage/default.png',
width_field='widthField',
height_field='heightField')
widthField = models.IntegerField(default=0)
heightField = models.IntegerField(default=0)
likes = models.PositiveIntegerField(default=0)
dislikes = models.PositiveIntegerField(default=0)
email = models.EmailField(blank=True)
mobileNo = models.CharField(max_length=14)
alternateMobileNo = models.CharField(max_length=15, blank=True)
location = gis_models.PointField(u'longitude/latitude',
geography=True, blank=True, null=True)
ownerName = models.CharField(blank=True,max_length=250)
shopAddress = models.TextField()
shopPinCode = models.PositiveIntegerField()
openingTime = models.TimeField()
closingTime = models.TimeField()
closingDay = MultiSelectField(choices=DAYS,default=DAYS[7][0])
isActive = models.BooleanField(default=0)
updatedAt = models.DateTimeField(auto_now=True)
timestamp = models.DateTimeField(auto_now_add=True)
gis = gis_models.GeoManager()
objects = models.Manager()
def __str__(self):
return self.shopName
Here is the picture of my time picker
This is picture of json format of openingTime which I am putting through rset api
my django admin (only lower part
请告诉我应该怎么做才能使时间输入字段的输入时间格式可接受
您必须更改数据库时间字段的格式..您不能更改输入时间格式