Custom Post Type Archives by Year & Month?

How do you display the archives of a Custom Post Type by Year & Month? 5 Yes, you can. All you need is make a filter for wp_get_archives(); so it accepts post_type parameter: function my_custom_post_type_archive_where($where,$args){ $post_type = isset($args[‘post_type’]) ? $args[‘post_type’] : ‘post’; $where = “WHERE post_type=”$post_type” AND post_status=”publish””; return $where; } then call this: add_filter( … Read more

the_date() not working

I am using wordpress 3.2 and I did a query post like this: <?php query_posts(“posts_per_page=1post=type&page=post_parent=10”);?> Then I try to echo out the date of this post I queried like this. <?php echo the_date(); ?> It gives me the title of the post and the excerpt and the permalink but no date. What do you think … Read more

Why is subtracting these two times (in 1927) giving a strange result?

If I run the following program, which parses two date strings referencing times Best Answerecond apart and compares them: public static void main(String[] args) throws ParseException { SimpleDateFormat sf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”); String str3 = “1927-12-31 23:54:07”; String str4 = “1927-12-31 23:54:08”; Date sDt3 = sf.parse(str3); Date sDt4 = sf.parse(str4); long ld3 = sDt3.getTime() … Read more

Java string to date conversion

That’s the hard way, and those java.util.Date setter methods have been deprecated since Java 1.1 (1997). Moreover, the whole java.util.Date class was de-facto deprecated (discommended) since introduction of java.time API in Java 8 (2014). Simply format the date using DateTimeFormatter with a pattern matching the input string (the tutorial is available here). In your specific case of “January 2, 2010” as the input … Read more

Change date format in a Java string

Use LocalDateTime#parse() (or ZonedDateTime#parse() if the string happens to contain a time zone part) to parse a String in a certain pattern into a LocalDateTime. String oldstring = “2011-01-18 00:00:00.0”; LocalDateTime datetime = LocalDateTime.parse(oldstring, DateTimeFormatter.ofPattern(“yyyy-MM-dd HH:mm:ss.S”)); Use LocalDateTime#format() (or ZonedDateTime#format()) to format a LocalDateTime into a String in a certain pattern. String newstring = datetime.format(DateTimeFormatter.ofPattern(“yyyy-MM-dd”)); System.out.println(newstring); // 2011-01-18 Or, when you’re not on Java 8 yet, use SimpleDateFormat#parse() to parse a String in … Read more