JS一些常用的日期操作

福尔摩斯对我笑 2019-05-18 5302 次 2037条

日期格式化

Date.prototype.FormatDate = function(dt){
    if( !dt){
      dt = new Date();
    }
    var year = dt.getFullYear();
    var month = dt.getMonth() + 1;
    var day = dt.getDate();
    if (month <= 10) {
      month = '0' + month;
    }

    if (day <= 10) {
      day = '0' + day;
    }
    return year + '-' + month + '-' + day;
}

 

获取当前时间对应的前X个月份


Date.prototype.GetCurrentBeforeTime = function(num){
    num =  !num ? 12: num; 
    var result = [];
    var date = new Date( new Date().setMonth(new Date().getMonth() + 1) );
	for(let i=0; i< num; i++){
		date.setMonth( date.getMonth() - 1) 
		let m = date.getMonth() +1 
		m = m < 10 ? "0" + m : m;
		result.push( date.getFullYear() + "-" + m + "-"  + date.getDate())
    }

    return result;
}

获取当前时间对应的英文格式月份

Date.prototype.GetCurrentEnMonth = function(times){
    //没有参数时返回当前月份
    if(!times || !(times instanceof Array) ){
        return new Date().toDateString().split(" ")[1];
    }

    let monthStr = [];
    times.forEach(elem=>{
		let month = new Date(elem).toDateString().split(" ")[1];
		monthStr.push( month)
    })
    
    return monthStr;
}
标签:

非特殊说明,本博所有文章均为博主原创。

头像也是LOGO
未来博客 博主大人
到了这个年纪,不应该再彷徨!

发表评论



 


已有 2037 条评论 1


  1. erotic

    You have made some good points there. I checked on the web for additional information about the issue and found most people will go along with your views on this site.

    回复 2020年2月26日
  2. son of a bitch

    Hello there! This article could not be written much better! Reading through this article reminds me of my previous roommate! He continually kept preaching about this. I’ll send this post to him. Pretty sure he will have a very good read. Thanks for sharing!

    回复 2020年2月26日
  3. Baltimore SEO

    An interesting discussion is worth comment. I believe that you should publish more on this subject, it might not be a taboo matter but generally folks don’t speak about such topics. To the next! Kind regards.

    回复 2020年2月26日
  4. whore

    Excellent web site you have got here.. It’s difficult to find good quality writing like yours nowadays. I honestly appreciate individuals like you! Take care!!

    回复 2020年2月26日
  5. coonnass

    Good post. I will be going through a few of these issues as well..

    回复 2020年2月26日
  6. god damn

    I couldn’t refrain from commenting. Well written!

    回复 2020年2月26日
  7. motherfuck

    Can I simply say what a relief to find a person that actually understands what they’re discussing online. You actually know how to bring an issue to light and make it important. A lot more people have to look at this and understand this side of your story. I was surprised that you aren’t more popular because you surely possess the gift.

    回复 2020年2月26日
  8. piss

    Having read this I thought it was very enlightening. I appreciate you taking the time and effort to put this content together. I once again find myself personally spending a lot of time both reading and leaving comments. But so what, it was still worthwhile!

    回复 2020年2月26日
  9. hard core

    After checking out a number of the blog articles on your blog, I honestly appreciate your technique of blogging. I book marked it to my bookmark website list and will be checking back soon. Take a look at my website as well and let me know your opinion.

    回复 2020年2月26日
  10. tienda budista en madrid

    you are in reality a good webmaster. The site loading pace is incredible. It sort of feels that you are doing any distinctive trick. Furthermore, The contents are masterpiece. you’ve done a fantastic task on this topic!

    回复 2020年2月26日
  11. bicicleta de carretera impar

    I am extremely impressed with your writing skills and also with the layout on your weblog. Is this a paid theme or did you modify it yourself? Either way keep up the nice quality writing, it is rare to see a nice blog like this one today..

    回复 2020年2月26日
  12. soccers streams Reddit

    Thanks , I have just been searching for information about this subject for ages and yours is the best I’ve came upon so far. But, what in regards to the bottom line? Are you sure concerning the source?

    回复 2020年2月26日
  13. free lesbian teen hd

    Does your site have a contact page? I’m having problems locating it but, I’d like to send you an email.
    I’ve got some suggestions for your blog you might be interested in hearing.
    Either way, great website and I look forward to seeing
    it expand over time.

    回复 2020年2月26日
  14. 남원출장마사지카톡- Po 3 4〖Poo3 4.c0M〗출장가격출장연애인급Y➥↘2019-04-09-07-55남원◄AIJ✪출장샵출장안마추천출장미인아가씨▧출장샵추천¤출장샵안내☼남원

    This is the right web site for everyone who hopes to understand this topic. You understand so much its almost tough to argue with you (not that I personally would want to…HaHa). You certainly put a new spin on a subject that has been discussed for many years. Excellent stuff, just wonderful!

    回复 2020年2月26日
  15. Abbruch aus Lübeck

    You’re so awesome! I do not suppose I have read through something like this before. So nice to find another person with a few unique thoughts on this topic. Really.. thanks for starting this up. This site is something that is needed on the web, someone with some originality.

    回复 2020年2月26日
  16. asshole

    I blog quite often and I genuinely thank you for your content. This great article has truly peaked my interest. I am going to take a note of your site and keep checking for new details about once per week. I subscribed to your RSS feed as well.

    回复 2020年2月26日
  17. tomatocraft.art.blog

    Heya! I just wanted to ask if you ever have any issues with hackers?
    My last blog (wordpress) was hacked and I ended up losing a few
    months of hard work due to no data backup. Do you have any
    solutions to prevent hackers?

    回复 2020年2月26日
  18. Rain GO NC

    You need to take part in a contest for one of the most useful websites online. I will recommend this blog!

    回复 2020年2月26日
  19. erotic

    You are so cool! I don’t believe I have read through a single thing like this before. So great to discover another person with unique thoughts on this issue. Seriously.. many thanks for starting this up. This website is one thing that is required on the web, someone with a little originality!

    回复 2020年2月26日
  20. 우리 카지노

    It is actually a great and helpful piece of info. I’m happy that you simply shared this
    useful info with us. Please stay us up to date like this.

    Thanks for sharing.

    回复 2020年2月26日
  21. lesbian

    Hello there! I just want to give you a big thumbs up for the great info you have right here on this post. I am coming back to your web site for more soon.

    回复 2020年2月26日
  22. King Weekly Sentinel

    Saved as a favorite, I love your website.

    回复 2020年2月26日
  23. a325tc

    My programmer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s tryiong none the less. I’ve been using Movable-type on various websites for about a year and am concerned about switching to another platform. I have heard good things about blogengine.net. Is there a way I can transfer all my wordpress content into it? Any kind of help would be greatly appreciated!

    回复 2020年2月25日
  24. Click here

    You’re so interesting! I don’t think I’ve truly read something like that before. So good to discover another person with a few genuine thoughts on this subject. Really.. many thanks for starting this up. This site is something that is required on the web, someone with some originality.

    回复 2020年2月25日
  25. lesbians

    You ought to be a part of a contest for one of the most useful websites on the internet. I am going to recommend this website!

    回复 2020年2月25日
  26. anus

    Howdy! I simply wish to offer you a huge thumbs up for the excellent info you have got right here on this post. I’ll be coming back to your website for more soon.

    回复 2020年2月25日
  27. 논산콜걸출장안마『카톡- Po 34』【Po o34.c0M】콜걸출장안마야한곳Y♞➹2019-02-27-15-32논산➷AIJ♤출장샵안내출장아가씨출장샵예약◘콜걸추천◆출장서비스보장┹논산

    I truly love your blog.. Excellent colors & theme. Did you develop this website yourself? Please reply back as I’m looking to create my very own blog and would love to know where you got this from or just what the theme is called. Thank you!

    回复 2020年2月25日
  28. crap

    Your style is so unique compared to other folks I’ve read stuff from. Thank you for posting when you have the opportunity, Guess I will just bookmark this site.

    回复 2020年2月25日
  29. bastard

    This is the right website for anyone who wants to find out about this topic. You realize so much its almost tough to argue with you (not that I personally will need to…HaHa). You certainly put a brand new spin on a topic which has been discussed for a long time. Wonderful stuff, just excellent!

    回复 2020年2月25日
  30. Garage Clean Out Raleigh NC

    There is certainly a lot to learn about this issue. I really like all of the points you have made.

    回复 2020年2月25日
  31. sadist

    After I originally left a comment I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on every time a comment is added I recieve 4 emails with the exact same comment. Perhaps there is a way you are able to remove me from that service? Appreciate it!

    回复 2020年2月25日
  32. https://joker123.dev/

    เป็นกำลังใจให้เจ้ทำคลิปต่อๆไปด้วยนะคะจุ๊บๆ ^^บิวตี้

    回复 2020年2月25日
  33. Florida Ozone Odor RemovalDescription: No More Odor Specializes in Smoke and Pet Odor Removal using Ozone throughout Florida

    No matter if some one searches for his required thing, thus he/she wants to be available that in detail, so
    that thing is maintained over here.

    回复 2020年2月25日
  34. ass hole

    Excellent blog you’ve got here.. It’s hard to find high quality writing like yours these days. I really appreciate people like you! Take care!!

    回复 2020年2月25日
  35. Best egusi soup in La

    That is a very good tip particularly to those fresh to the blogosphere. Brief but very precise info… Thank you for sharing this one. A must read article!

    回复 2020年2月25日
  36. 「순창콜걸」☴예약➦콜걸♧【카톡wyk92】♞〖птк455.сом〗순창K2019-03-19-19-08순창포항 아가씨Wl순창[][]순창┯순창qIn◊용암동 모텔F순창[]☁[]╖

    Your style is very unique in comparison to other folks I’ve read stuff from. I appreciate you for posting when you have the opportunity, Guess I will just book mark this page.

    回复 2020年2月25日
  37. 동해안마【카톡: Mo46】(Po o34.c0M)출장샵오피걸Y▒⇡2019-02-21-00-22동해☪AIJ✐출장아가씨출장미인아가씨오피걸┥출장샵후기♥출장서비스⇣동해

    You should take part in a contest for one of the finest websites on the net. I am going to recommend this site!

    回复 2020年2月25日
  38. https://images.google.so/url?q=httpswww.healthclues.net

    Hello to all, as I am genuinely eager of reading this
    web site’s post to be updated on a regular basis.
    It includes fastidious data.

    回复 2020年2月25日
  39. Best grapes (the fruit) in La

    Your style is so unique compared to other folks I have read stuff from. I appreciate you for posting when you have the opportunity, Guess I’ll just bookmark this page.

    回复 2020年2月25日
  40. motherfucker

    I could not refrain from commenting. Very well written!

    回复 2020年2月25日
  41. viagra

    There’s certainly a great deal to know about this subject. I like all of the points you have made.

    回复 2020年2月25日
  42. sex

    Very good info. Lucky me I recently found your website by chance (stumbleupon). I have saved it for later!

    回复 2020年2月25日
  43. anal

    I was more than happy to uncover this great site. I need to to thank you for ones time for this fantastic read!! I definitely loved every part of it and I have you book-marked to check out new stuff on your website.

    回复 2020年2月25日
  44. crap

    You are so awesome! I don’t suppose I’ve truly read through something like this before. So nice to find someone with some unique thoughts on this issue. Really.. thanks for starting this up. This web site is something that’s needed on the web, someone with a little originality!

    回复 2020年2月25日
  45. CBD

    You need to be a part of a contest for one of the highest quality websites on the internet. I’m going to highly recommend this web site!

    回复 2020年2月25日
  46. mother fucker

    Greetings! Very useful advice in this particular article! It is the little changes that make the largest changes. Many thanks for sharing!

    回复 2020年2月25日